1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! A runtime implementation that runs everything on the current thread.

mod arbiter;
pub(crate) mod block_pool;
mod builder;
mod context;
mod enter;
mod handle;
pub(crate) mod inner;
mod local;
mod runtime;
mod scheduler;
mod spawner;
mod system;

pub use self::arbiter::Arbiter;
pub use self::builder::{Builder, SystemRunner};
pub use self::runtime::Runtime;
pub use self::system::System;
pub use self::local::spawn_local;

use builder::BuilderInner;
use scheduler::BasicScheduler;
use block_pool::BlockingPool;
use enter::enter;
use local::LocalSet;
use handle::Handle;
use spawner::Spawner;
use inner::JoinHandle;

use std::future::Future;

/// Spawns a future on the current arbiter.
///
/// # Panics
///
/// This function panics if  system is not running.
pub fn spawn_fut<F>(f: F)
where
    F: futures_core::Future<Output = ()> + 'static,
{
    if !System::is_set() {
        panic!("System is not running");
    }

    Arbiter::spawn(f);
}

pub fn spawn<T>(task: T) -> JoinHandle<T::Output>
where
    T: Future + Send + 'static,
    T::Output: Send + 'static,
{
    context::spawn(task)
}


pub fn spawn_blocking<F, R>(f: F) -> JoinHandle<R>
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    block_pool::spawn_blocking(f)
}