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
//! Abstracts out the APIs necessary to `Runtime` for integrating the blocking
//! pool. When the `blocking` feature flag is **not** enabled, these APIs are
//! shells. This isolates the complexity of dealing with conditional
//! compilation.

cfg_blocking_impl! {
    mod pool;
    pub(crate) use pool::{spawn_blocking, BlockingPool, Spawner};

    mod schedule;
    mod shutdown;
    mod task;

    use crate::runtime::{self, Builder, io, time};

    pub(crate) fn create_blocking_pool(
        builder: &Builder,
        spawner: &runtime::Spawner,
        io: &io::Handle,
        time: &time::Handle,
        clock: &time::Clock,
    ) -> BlockingPool {
        BlockingPool::new(
            builder,
            spawner,
            io,
            time,
            clock)

    }
}

cfg_not_blocking_impl! {
    use crate::runtime::{self, io, time, Builder};

    #[derive(Debug, Clone)]
    pub(crate) struct BlockingPool {}

    pub(crate) use BlockingPool as Spawner;

    pub(crate) fn create_blocking_pool(
        _builder: &Builder,
        _spawner: &runtime::Spawner,
        _io: &io::Handle,
        _time: &time::Handle,
        _clock: &time::Clock,
    ) -> BlockingPool {
        BlockingPool {}
    }

    impl BlockingPool {
        pub(crate) fn spawner(&self) -> &BlockingPool {
            self
        }

        pub(crate) fn enter<F, R>(&self, f: F) -> R
        where
            F: FnOnce() -> R,
        {
            f()
        }
    }
}