mirror of https://github.com/stjepang/smol
Spawn onto local worker if possible
This commit is contained in:
parent
9e1a374559
commit
21fc108621
10
src/task.rs
10
src/task.rs
|
@ -102,11 +102,11 @@ impl<T: Send + 'static> Task<T> {
|
|||
///
|
||||
/// [`run()`]: `crate::run()`
|
||||
pub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T> {
|
||||
QUEUE.spawn(future)
|
||||
// WORKER.with(|w| match &*w.borrow() {
|
||||
// None => QUEUE.spawn(future),
|
||||
// Some(w) => w.spawn(future),
|
||||
// })
|
||||
if WORKER.is_set() {
|
||||
WORKER.with(|w| w.spawn_local(future))
|
||||
} else {
|
||||
QUEUE.spawn(future)
|
||||
}
|
||||
}
|
||||
|
||||
/// Spawns a future onto the blocking executor.
|
||||
|
|
Loading…
Reference in New Issue