mco_http/
runtime.rs

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