mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
async-runtime: add a way to spawn task using the runtime
Summary: This API will be used to spawn tasks in the runtime. Reviewed By: andll Differential Revision: D26615607 fbshipit-source-id: 6b9892fad755bbe8feb775e9dad457697b2ea1b7
This commit is contained in:
parent
a8d5625490
commit
3db2121dec
@ -26,6 +26,7 @@ use futures::future::Future;
|
||||
use futures::stream::{BoxStream, Stream, StreamExt};
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::runtime::{Builder as RuntimeBuilder, Runtime};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
|
||||
let nproc = num_cpus::get();
|
||||
@ -37,6 +38,15 @@ static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
|
||||
});
|
||||
pub static STREAM_BUFFER_SIZE: usize = 128;
|
||||
|
||||
/// Spawn a task using the runtime.
|
||||
pub fn spawn<T>(task: T) -> JoinHandle<T::Output>
|
||||
where
|
||||
T: Future + Send + 'static,
|
||||
T::Output: Send + 'static,
|
||||
{
|
||||
RUNTIME.spawn(task)
|
||||
}
|
||||
|
||||
/// Blocks the current thread while waiting for the computation defined by the Future `f` to
|
||||
/// complete.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user