mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

This adds initial, unstable, support for the wasm32-wasi target. Not all of Tokio's features are supported yet as WASI's non-blocking APIs are still limited. Refs: tokio-rs/tokio#4827
35 lines
889 B
Rust
35 lines
889 B
Rust
#![cfg(feature = "macros")]
|
|
|
|
use futures::channel::oneshot;
|
|
use futures::executor::block_on;
|
|
use std::thread;
|
|
|
|
#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")]
|
|
#[test]
|
|
fn join_with_select() {
|
|
block_on(async {
|
|
let (tx1, mut rx1) = oneshot::channel::<i32>();
|
|
let (tx2, mut rx2) = oneshot::channel::<i32>();
|
|
|
|
thread::spawn(move || {
|
|
tx1.send(123).unwrap();
|
|
tx2.send(456).unwrap();
|
|
});
|
|
|
|
let mut a = None;
|
|
let mut b = None;
|
|
|
|
while a.is_none() || b.is_none() {
|
|
tokio::select! {
|
|
v1 = (&mut rx1), if a.is_none() => a = Some(v1.unwrap()),
|
|
v2 = (&mut rx2), if b.is_none() => b = Some(v2.unwrap()),
|
|
}
|
|
}
|
|
|
|
let (a, b) = (a.unwrap(), b.unwrap());
|
|
|
|
assert_eq!(a, 123);
|
|
assert_eq!(b, 456);
|
|
});
|
|
}
|