Skip to content

Make async-nats independent on the runtime #1369

@pimeys

Description

@pimeys

Proposed change

Hey. I think we should make async-nats independent from tokio. While tokio remains the standard in the async Rust ecosystem, stable Rust has now standardized wasip2, and we can handle almost all IO with the second preview.

Tokio lacks wasip2 support. The team waits for mio to support it, but the pull request in mio has remained pending since last November without signs of merging soon.

Until Tokio adds support, we can use a temporary runtime in a p2 guest component: wstd

The lack of standardized Rust runtimes means we must use the runtime's TCP implementation. I want to examine the async-nats codebase to understand your tokio dependencies. Could we create a way to initialize nats by providing a socket that implements the AsyncRead and AsyncWrite traits? I hope you don't use tokio::spawn, or at least we could abstract these with a feature flag setup. The same applies to timers. This change shouldn't be too complex, and it would let us write wasip2 components that can use nats without implementing everything in the host.

Use case

To use nats in environments without tokio support.

Contribution

I am interested on providing a pull request, if this is a path you'd like to see for async-nats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalEnhancement idea or proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions