Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why startWorker() and not worker()? #58

Open
Tri0L opened this issue Apr 26, 2022 · 2 comments
Open

Why startWorker() and not worker()? #58

Tri0L opened this issue Apr 26, 2022 · 2 comments

Comments

@Tri0L
Copy link

Tri0L commented Apr 26, 2022

Hello!

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

workerpool/workerpool.go

Lines 192 to 200 in 85cc841

case p.workerQueue <- task:
default:
// Create a new worker, if not at max.
if workerCount < p.maxWorkers {
wg.Add(1)
go startWorker(task, p.workerQueue, &wg)
workerCount++
} else {
// Enqueue task to be executed by next available worker.

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 Tri0L changed the title Why startWorker() and not worker() Why startWorker() and not worker()? Apr 26, 2022
@F21
Copy link

F21 commented May 30, 2022

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.

@gammazero
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants