1
2use std::time::Duration;
3
4#[cfg(feature = "cogo")]
6pub type TcpListener = cogo::net::TcpListener;
7#[cfg(feature = "cogo")]
8pub type TcpStream = cogo::net::TcpStream;
9#[cfg(feature = "cogo")]
10pub type Receiver<T> = cogo::std::sync::channel::Receiver<T>;
11#[cfg(feature = "cogo")]
12pub type Sender<T> = cogo::std::sync::channel::Sender<T>;
13#[cfg(feature = "cogo")]
14pub type JoinHandle<T> = cogo::coroutine::JoinHandle<T>;
15#[cfg(feature = "cogo")]
16pub type Mutex<T> = cogo::std::sync::Mutex<T>;
17#[cfg(feature = "cogo")]
18pub type SyncBtreeMap<K,V> = cogo::std::map::SyncBtreeMap<K,V>;
19#[cfg(feature = "cogo")]
20pub type SyncHashMap<K,V> = cogo::std::map::SyncHashMap<K,V>;
21
22#[cfg(feature = "cogo")]
23pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
24 cogo::chan!()
25}
26
27#[cfg(feature = "cogo")]
28pub fn sleep(d: Duration) {
29 cogo::coroutine::sleep(d)
30}
31
32#[cfg(feature = "cogo")]
33pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
34 cogo::coroutine::Builder::new().stack_size(0x1000).spawn(f)
35}
36
37#[cfg(feature = "cogo")]
38pub fn spawn_stack_size<F>(f: F, stack_size:usize) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
39 cogo::coroutine::Builder::new().stack_size(stack_size).spawn(f)
40}
41
42
43#[cfg(not(feature = "cogo"))]
45pub type TcpListener = std::net::TcpListener;
46#[cfg(not(feature = "cogo"))]
47pub type TcpStream = std::net::TcpStream;
48#[cfg(not(feature = "cogo"))]
49pub type Receiver<T> = crossbeam::channel::Receiver<T>;
50#[cfg(not(feature = "cogo"))]
51pub type Sender<T> = crossbeam::channel::Sender<T>;
52#[cfg(not(feature = "cogo"))]
53pub type JoinHandle<T> = std::thread::JoinHandle<T>;
54#[cfg(not(feature = "cogo"))]
55pub type Mutex<T> = std::sync::Mutex<T>;
56#[cfg(not(feature = "cogo"))]
57pub type SyncBtreeMap<K,V> = dashmap::DashMap<K,V>;
58#[cfg(not(feature = "cogo"))]
59pub type SyncHashMap<K,V> = dashmap::DashMap<K,V>;
60
61#[cfg(not(feature = "cogo"))]
62pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
63 crossbeam::channel::unbounded()
64}
65
66#[cfg(not(feature = "cogo"))]
67pub fn sleep(d: Duration) {
68 std::thread::sleep(d)
69}
70
71#[cfg(not(feature = "cogo"))]
72pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
73 std::thread::spawn(f)
74}
75
76#[cfg(not(feature = "cogo"))]
77pub fn spawn_stack_size<F>(f: F, stack_size:usize) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
78 std::thread::spawn(f)
79}