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

Use stdweb spawn_local to execute futures #776

Closed
izissise opened this issue Dec 7, 2019 · 4 comments
Closed

Use stdweb spawn_local to execute futures #776

izissise opened this issue Dec 7, 2019 · 4 comments
Labels
feature-request A feature request

Comments

@izissise
Copy link
Contributor

izissise commented Dec 7, 2019

Description

Allow to use send_future with cargo web and asmjs-unknown-emscripten target by using stdweb spawn_local future feature.

An example of using future with stdweb https://github.com/koute/stdweb/blob/master/examples/futures/src/main.rs

Context (Environment)

  • Rust: v1.39.0 stable
  • yew: v0.10.0
  • target: asmjs-unknown-emscripten
  • cargo-web: v0.6.26
@ctaggart
Copy link
Contributor

ctaggart commented Dec 13, 2019

I realize this is different, but some may find it useful. I just tried using the spawn_local from wasm-bindgen for a function marked #[wasm_bindgen] and it worked. I'm using yew from master branch.

https://docs.rs/wasm-bindgen-futures/0.4.5/wasm_bindgen_futures/fn.spawn_local.html
https://github.com/rustwasm/wasm-bindgen/search?q=spawn_local&unscoped_q=spawn_local

@hgzimmerman
Copy link
Member

Oh, interesting.

Although it has since been removed and replaced with this stdweb based spawn_local in the yewtil crate, there are eventual plans to re-add a wasm-bindgen based implementation you could choose to use. This is more simple than the prior implementation, and should make gating either behind a feature flag much easier.

@ctaggart
Copy link
Contributor

With async move, I was able to call emit on branch_received: Callback<String>.

    spawn_local(async move {
        let branch = get_branch().await.unwrap_throw(); // vs unwrap?
        branch_received.emit(branch);
    });

@hgzimmerman
Copy link
Member

Since the corresponding PR in the appropriate repo was merged, I think that this issue can be closed.

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

No branches or pull requests

4 participants