Problem
Following up on #71, we still have some issues. In #70 (comment)@SilverMira provided the following failing test case:
#[test]fncooperative_concurrency(){crate::runtime::block_on(async{let cpu_heavy = asyncmove{// Simulating a CPU-heavy task that runs for 10 second and yields occasionallyfor _ in0..100{
std::thread::sleep(std::time::Duration::from_millis(100));
futures_lite::future::yield_now().await;}true};let timeout = asyncmove{crate::time::Timer::after(crate::time::Duration::from_secs(3)).wait().await;false};letmut 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:
https://github.com/yoshuawuyts/wstd/blob/90bb588c4f10030e2ac6fcdb13860d7da1a62b8d/src/runtime/block_on.rs#L40
Problem
Following up on #71, we still have some issues. In #70 (comment)@SilverMira provided the following failing test case:
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_pollableswhich callswasi::io::poll::pollon 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 thatwasi::io::poll::polldoes 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:https://github.com/yoshuawuyts/wstd/blob/90bb588c4f10030e2ac6fcdb13860d7da1a62b8d/src/runtime/block_on.rs#L40