Enable usage of timers on WASM
WASM targets don't support Async and probably won't until WASI reaches a more stable point. However, since parking is usable on WASM thanks to atomics, it may be desirable to use the Timer implementation.
My suggestion is to add two new features: io and timers. They compose as such:
- With both features enabled (they are by default), the crate functions as normal.
- With
iodisabled buttimersenabled, theReactorretains its timer processing capabilities but instead of calling topolling, it callsparking(which works with WASM) with the timeout resulting fromprocess_timer_ops. - With both features disabled,
Reactorno longer exists andblock_onis just an alias to the ones infutures_lite.
This would be a breaking change.
I'm not sure if we need to introduce such a breaking change to support WASM. Currently, async-io fails to compile on WASM anyway, so I think just disabling some APIs in WASM is not a problem.
That's probably the best way of going about this. I'll rearrange the PR I wrote to use OS flags instead of feature flags.
A few points of note I discovered while implementing this:
Instant::now()is unimplemented for WASM, which means we'd have to useinstantor something similar. However with the current API ofTimerthis means thatinstantwould be in the public API, unless we madeatorinterval_atunavailable for WASM.- In order for the condvar waiting to work, the
-Ctarget-feature=+atomicsflag needs to be enabled. However, trying to rebuild libstd with that gives me an ICE. I'll investigate more before I file a Rust bug.
Not relevant for now