-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
API proposal: tokio::task::try_spawn_blocking
#4955
Labels
Comments
lkts
added
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
labels
Aug 29, 2022
Yeah, since, as @ipetkov pointed out, the task::Builder::new()
.disable_blocking_queue() // name, obviously, subject to bikeshedding)
.spawn_blocking(|| { /* ... */ } and, we would add a tokio/tokio/src/runtime/blocking/pool.rs Lines 86 to 92 in cf181e8
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Is your feature request related to a problem? Please describe.
Currently
spawn_blocking
queues tasks if there is no free threads to execute it in blocking thread pool. This behavior may not be suitable for some applications:Describe the solution you'd like
I propose a
try_spawn_blocking
API.Alternatively (i don't know if it makes more sense implementation-wise but i suspect so)
try_spawn_blocking
can return a specialBlockingTaskJoinHandle
which will expose the error.Describe alternatives you've considered
Having a semaphore-based limiter on top of Tokio works well. Motivation for adding this API to Tokio is that:
The text was updated successfully, but these errors were encountered: