Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WidgetDriver: Use matrix_sdk_common::executor::spawn instead of tokio::spawn to make it wasm compatible. #4707

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

toger5
Copy link
Contributor

@toger5 toger5 commented Feb 22, 2025

Using the executer::spawn will select tokio::spawn or wasm_bindgen_futures::spawn_local based on what platform we are on.

They behave differently in that tokio actually starts the async block inside the spawn but the wasm spawn wrapper will only start the part that is not inside the async block and the join handle needs to be awaited for it to work.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@toger5
Copy link
Contributor Author

toger5 commented Feb 24, 2025

I think I need help on this since this is not the correct solution. When running on a non wasm platform the await will block.
So there seems to be an issue with

#[cfg(target_arch = "wasm32")]
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
where
    F: Future<Output = T> + 'static,
{
    let (future, remote_handle) = future.remote_handle();
    let (abort_handle, abort_registration) = AbortHandle::new_pair();
    let future = Abortable::new(future, abort_registration);

    wasm_bindgen_futures::spawn_local(async {
        // Poll the future, and ignore the result (either it's `Ok(())`, or it's
        // `Err(Aborted)`).

        let _ = future.await;
    });
    let j = JoinHandle { remote_handle: remote_handle, abort_handle };
    j.
}

Where we need to await the JoinHandle before the future is actually started on WASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant