-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Problem
Following up on #71, we still have some issues. In #70 (comment) @SilverMira provided the following failing test case:
#[test]
fn cooperative_concurrency() {
crate::runtime::block_on(async {
let cpu_heavy = async move {
// Simulating a CPU-heavy task that runs for 10 second and yields occasionally
for _ in 0..100 {
std::thread::sleep(std::time::Duration::from_millis(100));
futures_lite::future::yield_now().await;
}
true
};
let timeout = async move {
crate::time::Timer::after(crate::time::Duration::from_secs(3))
.wait()
.await;
false
};
let mut future_group = futures_concurrency::future::FutureGroup::<
Pin<Box<dyn std::future::Future<Output = bool>>>,
>::new();
future_group.insert(Box::pin(cpu_heavy));
future_group.insert(Box::pin(timeout));
let result = future_group.next().await;
assert_eq!(result, Some(false), "cpu_heavy task should have timed out");
});
}
From talking with @pchickey, it sounds like we are currently not calling the wakers before re-polling, which is causing the test to fail. We should write a patch to fix that.
Proposed Solution
The solution @pchickey is proposing is to add a non-blocking version of Reactor::block_on_pollables
which calls wasi::io::poll::poll
on every async pollable with a waker registered. We need a variation in the behavior that adds an additional pollable to the wasi poll list, so that wasi::io::poll::poll
does not block and immediately returns a ready list, and wakes all of the associated wakers. We should insert that call right below the following line:
Metadata
Metadata
Assignees
Labels
No labels