|
1 | 1 | # Crossfire |
2 | 2 |
|
3 | | -[]( |
4 | | -https://github.com/qingstor/crossfire-rs/actions) |
5 | | -[]( |
6 | | -https://github.com/qignstor/crossfire-rs#license) |
7 | | -[]( |
8 | | -https://crates.io/crates/crossfire) |
9 | | -[]( |
10 | | -https://docs.rs/crossfire) |
11 | | -[]( |
12 | | -https://www.rust-lang.org) |
| 3 | +NOTE: This project is no long maintain by qingstor team, has become a personal project. |
13 | 4 |
|
14 | | - |
15 | | -This crate provide channels used between async-async or async-blocking code, in all direction. |
16 | | -Implmented with lockless in mind, low level is based on crossbeam-channel |
17 | | - |
18 | | -## Performance |
19 | | - |
20 | | -Faster than channel in std or mpsc in tokio, slightly slower than crossbeam itself (since async overhead to wake up sender or receiver). |
21 | | - |
22 | | -Run the benchmark tests to see for yourself: |
23 | | - |
24 | | - cargo test performance --release -- --nocapture --test-threads=1 |
25 | | - |
26 | | - |
27 | | -## APIs |
28 | | - |
29 | | - |
30 | | -## Usage |
31 | | - |
32 | | -Add this to your `Cargo.toml`: |
33 | | - |
34 | | -```toml |
35 | | -[dependencies] |
36 | | -crossfire = "0.1" |
37 | | -``` |
38 | | - |
39 | | -```rust |
40 | | - |
41 | | -extern crate crossfire; |
42 | | -extern crate tokio; |
43 | | - |
44 | | -use crossfire::mpsc; |
45 | | - |
46 | | -// async-async |
47 | | - |
48 | | -let (tx, rx) = mpsc::bounded_future_both::<i32>(100); |
49 | | -tokio::spawn(async move { |
50 | | - for i in 0i32..10000 { |
51 | | - let _ = tx.send(i).await; |
52 | | - println!("sent {}", i); |
53 | | - } |
54 | | -}); |
55 | | - |
56 | | -loop { |
57 | | - if let Ok(_i) = rx.recv().await { |
58 | | - println!("recv {}", _i); |
59 | | - } else { |
60 | | - println!("rx closed"); |
61 | | - break; |
62 | | - } |
63 | | -} |
64 | | - |
65 | | -``` |
66 | | - |
67 | | -mpmc & mpsc package is almost the same, while mpsc has some optimization becauses it assumes only one consumer. |
68 | | - |
69 | | -Error types are re-exported from crossbeam-channel. |
70 | | - |
71 | | - |
72 | | -## Compatibility |
73 | | - |
74 | | -Supports stable Rust. Mainly tested on tokio-0.2 (Not tested on async-std or other runtime). |
75 | | -future::selects and timeout work fine, but it takes advantage of runtime behavior not documented by Rust official. |
76 | | - |
77 | | -Refer to https://github.com/rust-lang/rust/issues/73002 |
78 | | - |
79 | | - |
80 | | -## Memory overhead |
81 | | - |
82 | | -While using mp tx or mp rx, there's memory overhead to pass along wakers for pending async producer or consumer. |
83 | | -Since waker is small, the overhead can be ignored if your channel is busy. |
84 | | -Canceled wakers will be eventually cleanup by later send/receive event. |
85 | | -If the channel is used for close notification (which never trigger) in combine with futures::select, |
86 | | -currently there's hard coded threshold to clean up those canceled wakers. |
87 | | - |
88 | | -## Stability |
89 | | - |
90 | | -This channel implementation serves in various components of our storage engine, you are |
91 | | -welcome to rely on it. |
| 5 | +for Issue and bug, please jump to https://github.com/frostyplanet/crossfire-rs |
0 commit comments