<commit_before># go_workerpool
Generic worker pool for Go Language. You can limit the number of go routines which are running in parallel.

## Travis CI
![Travis CI](https://travis-ci.org/vladiacob/go_workerpool.svg)

## Godoc
[https://godoc.org/github.com/vladiacob/go_workerpool](https://godoc.org/github.com/vladiacob/go_workerpool)

## How to install
```
go get github.com/vladiacob/go_workerpool
```

## How to run examples
```
cd examples
go run example.go
```

## How to use
### Include go_workerpool
```
include (
    ..
    pool "github.com/vladiacob/go_workerpool"
    ..
)
```

### Initialize pool
```
workerPool := pool.New(2, 10)
workerPool.Run()
```
* maxWorkers: number of workers which are processing in parallel
* maxJobQueue: number of jobs which will be accept in queue

### Add job to pool
```
err := workerPool.Add(job1)
if err != nil {
    fmt.Println(err)
}
```

### Stop worker pool
```
err := workerPool.Stop(true)
if err != nil {
    fmt.Println(err)
}
```
* waitAndStop == true: wait until all jobs was processed
* waitAndStop == false: close workers immediate 

### Job example
```
// Job structure
type Job struct {
    name string
}

// Work is method which is called by the worker
func (j *Job) Work() error {
    fmt.Println("Work: " + j.name)

    time.Sleep(1 * time.Second)

    return nil
}
```<commit_msg>Added SetWorkerID in README.md<commit_after># go_workerpool
Generic worker pool for Go Language. You can limit the number of go routines which are running in parallel.

## Travis CI
![Travis CI](https://travis-ci.org/vladiacob/go_workerpool.svg)

## Godoc
[https://godoc.org/github.com/vladiacob/go_workerpool](https://godoc.org/github.com/vladiacob/go_workerpool)

## How to install
```
go get github.com/vladiacob/go_workerpool
```

## How to run examples
```
cd examples
go run example.go
```

## How to use
### Include go_workerpool
```
include (
    ..
    pool "github.com/vladiacob/go_workerpool"
    ..
)
```

### Initialize pool
```
workerPool := pool.New(2, 10)
workerPool.Run()
```
* maxWorkers: number of workers which are processing in parallel
* maxJobQueue: number of jobs which will be accept in queue

### Add job to pool
```
err := workerPool.Add(job1)
if err != nil {
    fmt.Println(err)
}
```

### Stop worker pool
```
err := workerPool.Stop(true)
if err != nil {
    fmt.Println(err)
}
```
* true: wait until all jobs was processed
* false: close workers immediate 

### Job example
```
// Job structure
type Job struct {
    name string
}

// Work is method which is called by the worker
func (j *Job) Work() error {
    fmt.Println("Work: " + j.name)

    time.Sleep(1 * time.Second)

    return nil
}

func (j *Job) SetWorkerID(ID int) {
    j.workerID = ID
}
```
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.003663003663003663, 'mean_word_length': 3.668376068376068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '1286677', 'n_tokens_mistral': 969, 'n_tokens_neox': 920, 'n_words': 280}