Skip to content

Enable usage of timers on WASM #89

@notgull

Description

@notgull
Member

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 io disabled but timers enabled, the Reactor retains its timer processing capabilities but instead of calling to polling, it calls parking (which works with WASM) with the timeout resulting from process_timer_ops.
  • With both features disabled, Reactor no longer exists and block_on is just an alias to the ones in futures_lite.

This would be a breaking change.

Activity

taiki-e

taiki-e commented on Sep 8, 2022

@taiki-e
Collaborator

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.

notgull

notgull commented on Sep 8, 2022

@notgull
MemberAuthor

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.

notgull

notgull commented on Dec 1, 2022

@notgull
MemberAuthor

A few points of note I discovered while implementing this:

  • Instant::now() is unimplemented for WASM, which means we'd have to use instant or something similar. However with the current API of Timer this means that instant would be in the public API, unless we made at or interval_at unavailable for WASM.
  • In order for the condvar waiting to work, the -Ctarget-feature=+atomics flag 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.
notgull

notgull commented on Feb 4, 2024

@notgull
MemberAuthor

Not relevant for now

changed the title [-]Optionally disable timers or Asyncs on features[/-] [+]Enable usage of timers on WASM[/+] on Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @notgull@taiki-e

      Issue actions

        Enable usage of timers on WASM · Issue #89 · smol-rs/async-io