mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
Enable thread pool for blocking ops (#3912)
This commit is contained in:
parent
99186dbaa2
commit
724e39f13f
2 changed files with 4 additions and 11 deletions
|
@ -103,15 +103,7 @@ where
|
||||||
if is_sync {
|
if is_sync {
|
||||||
Ok(JsonOp::Sync(f()?))
|
Ok(JsonOp::Sync(f()?))
|
||||||
} else {
|
} else {
|
||||||
// TODO(ry) use thread pool.
|
let fut = async move { tokio::task::spawn_blocking(f).await.unwrap() };
|
||||||
let fut = crate::tokio_util::spawn_thread(f);
|
|
||||||
/*
|
|
||||||
let fut = async move {
|
|
||||||
tokio::task::spawn_blocking(move || f())
|
|
||||||
.await
|
|
||||||
.map_err(ErrBox::from)?
|
|
||||||
}.boxed_local();
|
|
||||||
*/
|
|
||||||
Ok(JsonOp::Async(fut.boxed_local()))
|
Ok(JsonOp::Async(fut.boxed_local()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
use futures::Future;
|
|
||||||
|
|
||||||
// TODO(ry) rename to run_local ?
|
// TODO(ry) rename to run_local ?
|
||||||
pub fn run_basic<F, R>(future: F) -> R
|
pub fn run_basic<F, R>(future: F) -> R
|
||||||
|
@ -15,7 +14,9 @@ where
|
||||||
rt.block_on(future)
|
rt.block_on(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_thread<F, R>(f: F) -> impl Future<Output = R>
|
// TODO(ry) maybe replace with tokio::task::spawn_blocking
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn spawn_thread<F, R>(f: F) -> impl std::future::Future<Output = R>
|
||||||
where
|
where
|
||||||
F: 'static + Send + FnOnce() -> R,
|
F: 'static + Send + FnOnce() -> R,
|
||||||
R: 'static + Send,
|
R: 'static + Send,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue