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

Wait on Submit until queue has #71

Open
janekolszak opened this issue Feb 21, 2023 · 1 comment
Open

Wait on Submit until queue has #71

janekolszak opened this issue Feb 21, 2023 · 1 comment

Comments

@janekolszak
Copy link

Hi,
I'm in a need of blocking Submit until the queue of tasks is small enough.
I imagine something like SubmitBlock( ctx context.Context, minQueueDepth uint, f func()) that waits for the queue to be small enough, inserts the func and immediately returns.

Would you like to add something like that or accept a PR?

@toqueteos
Copy link

Here's the workaround I'm using until workerpool supports customizable queue size:

var stop bool
for !stop {
	if pool.WaitingQueueSize() > DESIRED_QUEUE_SIZE {
		time.Sleep(CUSTOM_DURATION) // exponential backoff would probably be better
		continue
	}
	pool.Submit(func() {
		// ...
	})
}

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

2 participants