yewstack / prokio

An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets.
Apache License 2.0
68 stars 7 forks source link

Support tokio for platforms without multi-threading support #12

Closed futursolo closed 10 months ago

futursolo commented 11 months ago

Description

@langyo

This pull request consists of the following changes:

Checklist

futursolo commented 10 months ago

After some consideration, I think it is not possible to replicate the behaviour described in test test_spawn_local_within_send. Since it is not possible to automatically register a LocalSet for tasks spawned by tokio::spawn to enable prokio::spawn_local when a task is not running in a dedicated prokio worker thread, This results in hard to explain behaviour and contradicts how prokio works with multi-threading support.


use prokio::Runtime;

let runtime = Runtime::default();

runtime.spawn_pinned(|| async {
    tokio::spawn(async {
        prokio::spawn_local(async {
            // Despite running within prokio runtime,
            // this does not work without dedicated worker thread.
        });
    });
});

For now, I think it is better to assume outside-runtime behaviour for prokio. Where a LocalSet is explicitly required to use LocalServerRenderer.

Since most web frameworks in tokio uses Send futures, I do expect issues with most web frameworks. However, the only way to solve this properly is to wait std::thread support for wasm32-wasi.