workerpool icon indicating copy to clipboard operation
workerpool copied to clipboard

Why startWorker() and not worker()?

Open Tri0L opened this issue 2 years ago • 2 comments

Hello!

Why are you using startWorker() and not worker()?

https://github.com/gammazero/workerpool/blob/85cc841576f67b14360c7298da3bcbbb76757020/workerpool.go#L192-L200

Maybe you have some examples, how I can pass db connection to worker? Not to specific task. Main idea is: Up some workers with 1 connection per worker and do sql requests(tasks) using worker sql connection.

Tri0L avatar Apr 26 '22 20:04 Tri0L

I am interested in doing something similar to this as well. Maybe there needs to be a worker interface that we can use to create our own custom workers that will then be started and stopped by the pool.

F21 avatar May 30 '22 23:05 F21

Why are you using startWorker() and not worker()?

When starting a new worker, that new worker to run the new task directly, instead of pulling it off the work queue. Since the behavior was slightly different when starting, I split it into two functions. Other than that, there is no reason it cannot be the same function. That change to use the same function and goroutine was made in #59.

gammazero avatar Aug 12 '22 18:08 gammazero