<commit_before>Library pool
============

[![GoDoc](https://godoc.org/github.com/joeybloggs/pool?status.svg)](https://godoc.org/github.com/joeybloggs/pool)

Library pool implements a consumer goroutine pool for easier goroutine handling. 

Features:

-    Dead simple to use and makes no assumptions about how you will use it.
-    Automatic recovery from consumer goroutines which returns an error to the results + automatically cancels the rest of the jobs.

Installation
------------

Use go get.

	go get github.com/joeybloggs/pool

or to update

	go get -u github.com/joeybloggs/pool

Then import the validator package into your own code.

	import "github.com/joeybloggs/pool"

Usage and documentation
------

Please see http://godoc.org/github.com/joeybloggs/pool for detailed usage docs.

##### Examples:

Struct return value
```go
package main

import (
	"errors"
	"fmt"
	"time"

	"github.com/joeybloggs/pool"
)

type resultStruct struct {
	i   int
	err error
}

func main() {
	p := pool.NewPool(4, 16)

	fn := func(job *pool.Job) {

		i := job.Params()[0].(int)

		res := &resultStruct{
			i: i,
		}

		// any condition that would cause an error
		if i == 10 {
			res.err = errors.New("Something bad happened, but don't need to cancel the rest of the jobs")
			job.Return(res)
			// or if you want to cancel run the line below
			job.Cancel()
			return
		}

		time.Sleep(time.Second * 1)
		job.Return(res)
	}

	for i := 0; i < 4; i++ {
		p.Queue(fn, i)
	}

	for result := range p.Results() {

		res := result.(*resultStruct)

		if res.err != nil {
			// do what you want with error or cancel the pool here p.Cancel()
			fmt.Println(res.err)
		}

		// do what you want with result
		fmt.Println(res.i)
	}
}
```

Value return value
```go
package main

import (
	"errors"
	"fmt"<commit_msg>update example in README for recovery<commit_after>Library pool
============

[![GoDoc](https://godoc.org/github.com/joeybloggs/pool?status.svg)](https://godoc.org/github.com/joeybloggs/pool)

Library pool implements a consumer goroutine pool for easier goroutine handling. 

Features:

-    Dead simple to use and makes no assumptions about how you will use it.
-    Automatic recovery from consumer goroutines which returns an error to the results + automatically cancels the rest of the jobs.

Installation
------------

Use go get.

	go get github.com/joeybloggs/pool

or to update

	go get -u github.com/joeybloggs/pool

Then import the validator package into your own code.

	import "github.com/joeybloggs/pool"

Usage and documentation
------

Please see http://godoc.org/github.com/joeybloggs/pool for detailed usage docs.

##### Examples:

Struct return value
```go
package main

import (
	"errors"
	"fmt"
	"time"

	"github.com/joeybloggs/pool"
)

type resultStruct struct {
	i   int
	err error
}

func main() {
	p := pool.NewPool(4, 16)

	fn := func(job *pool.Job) {

		i := job.Params()[0].(int)

		res := &resultStruct{
			i: i,
		}

		// any condition that would cause an error
		if i == 10 {
			res.err = errors.New("Something bad happened, but don't need to cancel the rest of the jobs")
			job.Return(res)
			// or if you want to cancel run the line below
			job.Cancel()
			return
		}

		time.Sleep(time.Second * 1)
		job.Return(res)
	}

	for i := 0; i < 4; i++ {
		p.Queue(fn, i)
	}

	for result := range p.Results() {

		err, ok := result.(error)
		if ok {
			// there was some sort of panic that
			// was recovered, in this scenario
			fmt.Println(err)
			return
		}

		res := result.(*resultStruct)

		if res.err != nil {
			// do what you want with error or cancel the pool here p.Cancel()
			fmt.Println(res.err)
		}

		// do what you want with result
		fmt.Println(res.i)
	}
}
```

Value return value
```go
package main

import (
	"errors"
	"fmt"
{'fraction_non_alphanumeric': 0.13007698433766923, 'fraction_numerical': 0.004778338200159278, 'mean_word_length': 3.012779552715655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3761239', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1269, 'n_words': 427}