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
65
66
67
68
69
70
71
72
73
74

use std::time::Duration;

/// if use mco runtime
#[cfg(feature = "mco")]
pub type TcpListener = mco::net::TcpListener;
#[cfg(feature = "mco")]
pub type TcpStream = mco::net::TcpStream;
#[cfg(feature = "mco")]
pub type Receiver<T> = mco::std::sync::channel::Receiver<T>;
#[cfg(feature = "mco")]
pub type Sender<T> = mco::std::sync::channel::Sender<T>;
#[cfg(feature = "mco")]
pub type JoinHandle<T> = mco::coroutine::JoinHandle<T>;
#[cfg(feature = "mco")]
pub type Mutex<T> = mco::std::sync::Mutex<T>;
#[cfg(feature = "mco")]
pub type SyncBtreeMap<K,V> = mco::std::sync::SyncBtreeMap<K,V>;
#[cfg(feature = "mco")]
pub type SyncHashMap<K,V> = mco::std::sync::SyncHashMap<K,V>;

#[cfg(feature = "mco")]
pub type SyncVec<V> = mco::std::sync::SyncVec<V>;

#[cfg(feature = "mco")]
pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
    mco::chan!()
}

#[cfg(feature = "mco")]
pub fn sleep(d: Duration) {
    mco::coroutine::sleep(d)
}

#[cfg(feature = "mco")]
pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + Send + 'static {
    mco::coroutine::Builder::new().spawn(f)
}


/// if not mco
#[cfg(not(feature = "mco"))]
pub type TcpListener = std::net::TcpListener;
#[cfg(not(feature = "mco"))]
pub type TcpStream = std::net::TcpStream;
#[cfg(not(feature = "mco"))]
pub type Receiver<T> = crossbeam::channel::Receiver<T>;
#[cfg(not(feature = "mco"))]
pub type Sender<T> = crossbeam::channel::Sender<T>;
#[cfg(not(feature = "mco"))]
pub type JoinHandle<T> = std::thread::JoinHandle<T>;
#[cfg(not(feature = "mco"))]
pub type Mutex<T> = std::sync::Mutex<T>;
#[cfg(not(feature = "mco"))]
pub type SyncBtreeMap<K,V> = dark_std::sync::SyncBtreeMap<K,V>;
#[cfg(not(feature = "mco"))]
pub type SyncHashMap<K,V> = dark_std::sync::SyncHashMap<K,V>;
#[cfg(not(feature = "mco"))]
pub type SyncVec<V> = dark_std::sync::SyncVec<V>;

#[cfg(not(feature = "mco"))]
pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
    crossbeam::channel::unbounded()
}

#[cfg(not(feature = "mco"))]
pub fn sleep(d: Duration) {
    std::thread::sleep(d)
}

#[cfg(not(feature = "mco"))]
pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
    std::thread::spawn(f)
}