Skip to content

Single-threaded async runtime #11170

Open
@HoKim98

Description

@HoKim98

Feature

I want to use wasmtime in actix-web, which uses !Send runtime and resources such as HTTPRequest and web::Payload.

But the current runtime requires functions and states to be Sendable.

I thought it's not mandatory to enforce Send trait.
So I have tested on my local without Send and found no problem.

Benefit

We can use wasmtime in the thread-bounded (single-threaded) async runtimes.

It's essential to use wasmtime within actix ecosystem, which provides the input parameters as !Send.

Implementation

My current(initial) idea is to create buddy methods like below:

/// Original method
pub async fn instantiate_async(
    &self,
    mut store: impl AsContextMut<Data = T>,
) -> Result<Instance>
where
    T: Send,
{
    let mut store = store.as_context_mut();
    assert!(
        store.0.async_support(),
        "must use sync instantiation when async support is disabled"
    );
    store.on_fiber(|store| self.instantiate_impl(store)).await?
}

/// (New) buddy method
pub async fn instantiate_async_single_rt(
    &self,
    mut store: impl AsContextMut<Data = T>,
) -> Result<Instance> {
    let mut store = store.as_context_mut();
    assert!(
        store.0.async_support(),
        "must use sync instantiation when async support is disabled"
    );
    store
        .on_fiber_single_rt(|store| self.instantiate_impl_single_rt(store))
        .await?
}
  • The estimated number of new lines: 100~500
  • Side-effect: no

Alternatives

My another idea is to use cargo features like async-send.
But I think it may break the ecosystem (side-effect).

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