https://github.com/onsails/tokio-non-async
https://github.com/onsails/tokio-non-async
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/onsails/tokio-non-async
- Owner: onsails
- License: mit
- Created: 2020-07-18T14:56:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T22:41:03.000Z (almost 6 years ago)
- Last Synced: 2025-07-17T21:32:52.901Z (11 months ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Helpers for dealing with tokio channels from non-async code in a blocking manner
```rust
let (mut tx, mut rx) = mpsc::channel(10);
for i in 0i32..10 {
tx.send(i).await.unwrap();
}
drop(tx);
tokio::task::spawn_blocking(move || {
while let Some(received) = rx.optimistic_blocking_recv() {
let received = rx.optimistic_blocking_recv();
some_blocking_op(received);
}
})
.await
.unwrap();
```