Skip to content

Commit 3fe6357

Browse files
authored
Merge pull request #191 from zed-industries/async-dispatcher-feature
Introduce async-dispatcher runtime feature
2 parents d3ed228 + 6d9ce5a commit 3fe6357

File tree

10 files changed

+44
-10
lines changed

10 files changed

+44
-10
lines changed

.github/workflows/main-ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ jobs:
5959
with:
6060
command: test
6161
args: --all --no-default-features --features async-std-runtime,all-transport
62+
- name: Test Async-dispatcher version
63+
uses: actions-rs/cargo@v1
64+
with:
65+
command: test
66+
args: --all --no-default-features --features async-dispatcher-runtime,all-transport
6267

6368
fmt:
6469
name: Formatting

Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ rust-version = "1.62.0"
1212
default = ["tokio-runtime", "all-transport"]
1313
tokio-runtime = ["tokio", "tokio-util"]
1414
async-std-runtime = ["async-std"]
15+
async-dispatcher-runtime = ["async-std", "async-dispatcher"]
1516
all-transport = ["ipc-transport", "tcp-transport"]
1617
ipc-transport = []
1718
tcp-transport = []
1819

1920
[dependencies]
21+
async-dispatcher = { version = "0.1", optional = true }
2022
thiserror = "1"
2123
futures-channel = { version = "0.3", features = ["sink"] }
2224
futures-io = "0.3"
@@ -32,13 +34,17 @@ num-traits = "0.2"
3234
dashmap = "5"
3335
crossbeam-queue = "0.3"
3436
uuid = { version = "1", features = ["v4"] }
35-
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
37+
regex = { version = "1", default-features = false, features = [
38+
"std",
39+
"unicode-perl",
40+
] }
3641
once_cell = "1"
3742
log = "0.4"
3843
asynchronous-codec = "0.7"
3944
async-std = { version = "1", features = ["attributes"], optional = true }
4045

4146
[dev-dependencies]
47+
async-dispatcher = { version = "0.1", features = ["macros"] }
4248
chrono = "0.4"
4349
criterion = "0.5"
4450
pretty_env_logger = "0.5"

benches/req_rep.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ async fn setup(endpoint: &str) -> (ReqSocket, RepSocket) {
2525
fn criterion_benchmark(c: &mut Criterion) {
2626
#[cfg(feature = "tokio-runtime")]
2727
type Runtime = tokio::runtime::Runtime;
28-
#[cfg(feature = "async-std-runtime")]
28+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
2929
type Runtime = ();
3030

3131
#[cfg(feature = "tokio-runtime")]
3232
let mut rt = tokio::runtime::Runtime::new().unwrap();
33-
#[cfg(feature = "async-std-runtime")]
33+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
3434
let mut rt = ();
3535

3636
const N_MSG: u32 = 512;
@@ -48,6 +48,8 @@ fn criterion_benchmark(c: &mut Criterion) {
4848
let (req, rep) = rt.block_on(setup(endpoint));
4949
#[cfg(feature = "async-std-runtime")]
5050
let (req, rep) = async_std::task::block_on(setup(endpoint));
51+
#[cfg(feature = "async-dispatcher-runtime")]
52+
let (req, rep) = async_dispatcher::block_on(setup(endpoint));
5153

5254
let (mut req, mut rep) = (Some(req), Some(rep));
5355

@@ -57,6 +59,8 @@ fn criterion_benchmark(c: &mut Criterion) {
5759
rt.block_on(iter_fn(&mut req, &mut rep));
5860
#[cfg(feature = "async-std-runtime")]
5961
async_std::task::block_on(iter_fn(&mut req, &mut rep));
62+
#[cfg(feature = "async-dispatcher-runtime")]
63+
async_dispatcher::block_on(iter_fn(&mut req, &mut rep));
6064
})
6165
});
6266
}

examples/async_helpers/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ pub async fn sleep(duration: std::time::Duration) {
2222
pub async fn sleep(duration: std::time::Duration) {
2323
async_std::task::sleep(duration).await
2424
}
25+
26+
#[allow(unused_imports)]
27+
#[cfg(feature = "async-dispatcher-runtime")]
28+
pub use async_dispatcher::{main, test};
29+
30+
#[allow(unused)]
31+
#[cfg(feature = "async-dispatcher-runtime")]
32+
pub use async_dispatcher::sleep;

src/async_rt/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ pub use tokio::{main, test};
1111
extern crate async_std;
1212
#[cfg(feature = "async-std-runtime")]
1313
pub use async_std::{main, test};
14+
15+
#[cfg(feature = "async-dispatcher-runtime")]
16+
pub use async_dispatcher::{main, test};

src/async_rt/task/join_handle.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "async-dispatcher-runtime")]
2+
use async_dispatcher as rt_task;
13
#[cfg(feature = "async-std-runtime")]
24
use async_std::task as rt_task;
35
#[cfg(feature = "tokio-runtime")]
@@ -17,7 +19,7 @@ impl<T> Future for JoinHandle<T> {
1719
// In async-std, the program aborts on panic so results arent returned. To
1820
// unify with tokio, we simply make an `Ok` result.
1921
let result = rt_task::JoinHandle::poll(Pin::new(&mut self.0), cx);
20-
#[cfg(feature = "async-std-runtime")]
22+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
2123
return result.map(Ok);
2224
#[cfg(feature = "tokio-runtime")]
2325
return result.map_err(|e| e.into());

src/async_rt/task/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ where
1515
let result = tokio::task::spawn(task).into();
1616
#[cfg(feature = "async-std-runtime")]
1717
let result = async_std::task::spawn(task).into();
18+
#[cfg(feature = "async-dispatcher-runtime")]
19+
let result = async_dispatcher::spawn(task).into();
1820

1921
result
2022
}
@@ -54,7 +56,9 @@ pub async fn sleep(duration: std::time::Duration) {
5456
#[cfg(feature = "tokio-runtime")]
5557
::tokio::time::sleep(duration).await;
5658
#[cfg(feature = "async-std-runtime")]
57-
::async_std::task::sleep(duration).await
59+
::async_std::task::sleep(duration).await;
60+
#[cfg(feature = "async-dispatcher-runtime")]
61+
::async_dispatcher::sleep(duration).await;
5862
}
5963

6064
pub async fn timeout<F, T>(
@@ -68,6 +72,8 @@ where
6872
let result = ::tokio::time::timeout(duration, f).await?;
6973
#[cfg(feature = "async-std-runtime")]
7074
let result = ::async_std::future::timeout(duration, f).await?;
75+
#[cfg(feature = "async-dispatcher-runtime")]
76+
let result = ::async_dispatcher::timeout(duration, f).await?;
7177

7278
Ok(result)
7379
}

src/transport/ipc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "tokio-runtime")]
22
use tokio::net::{UnixListener, UnixStream};
33

4-
#[cfg(feature = "async-std-runtime")]
4+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
55
use async_std::os::unix::net::{UnixListener, UnixStream};
66

77
use super::make_framed;
@@ -39,7 +39,7 @@ where
3939

4040
#[cfg(feature = "tokio-runtime")]
4141
let listener = UnixListener::bind(path)?;
42-
#[cfg(feature = "async-std-runtime")]
42+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
4343
let listener = UnixListener::bind(path).await?;
4444

4545
let resolved_addr = listener.local_addr()?;
@@ -65,7 +65,7 @@ where
6565
}
6666
drop(listener);
6767
if let Some(listener_addr) = listener_addr {
68-
#[cfg(feature = "async-std-runtime")]
68+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
6969
use async_std::fs::remove_file;
7070
#[cfg(feature = "tokio-runtime")]
7171
use tokio::fs::remove_file;

src/transport/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ where
101101
}
102102

103103
#[allow(unused)]
104-
#[cfg(feature = "async-std-runtime")]
104+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
105105
fn make_framed<T>(stream: T) -> FramedIo
106106
where
107107
T: futures_io::AsyncRead + futures_io::AsyncWrite + Send + Sync + 'static,

src/transport/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "tokio-runtime")]
22
use tokio::net::{TcpListener, TcpStream};
33

4-
#[cfg(feature = "async-std-runtime")]
4+
#[cfg(any(feature = "async-std-runtime", feature = "async-dispatcher-runtime"))]
55
use async_std::net::{TcpListener, TcpStream};
66

77
use super::make_framed;

0 commit comments

Comments
 (0)