Skip to content

Instant is not available on WASM + Proposed Solution #926

@ryanisaacg

Description

@ryanisaacg

Instant is part of the public API of EventLoop 2.0, which makes sense but unfortunately Instant cannot be constructed on WASM. As of right now, wasm (via stdweb or wasm-bindgen) is essentially only able to access core and alloc.

One solution is to wait until Instant becomes available on wasm via the experimental system call interface. However, there is no timeline for this and it's not clear how long that will take.

What I propose is winit have its own Instant type, with an API identical to std::time::Instant, except it has a private constructor that allows wasm to construct instances of it from web time APIs. The upside is that the public API is more or less the same and fully compatible with wasm; the downside is that users may be confused about why winit has its own Instant type. A possible fix for that would be to intentionally change the type's name to a synonym like Timestamp, so that it is obviously distinct from the type in the standard library.

I would be willing to make the change as part of #797 as long as the maintainers of other platforms would be amenable to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions