emilk / ehttp

Minimal Rust HTTP client for both native and WASM
Apache License 2.0
323 stars 30 forks source link

Fetching using channels #22

Closed EvoTeamDevelop closed 1 year ago

EvoTeamDevelop commented 1 year ago

Currently I am trying to use channels receiver for wasm runtime:

let (sender, receiver) = mpsc::channel();

ehttp::fetch(ehttp::Request::get(&url), move |response: ehttp::Result<ehttp::Response>| {
    let result = response.unwrap();

    sender.send(result);
});
...
let response = receiver.recv().unwrap();

But it fails with error - panicked at 'condvar wait not supported', library/std/src/sys/wasm/../unsupported/locks/condvar.rs:20:9:

Screenshot 2023-02-28 at 16 45 47

As I get it from other internet resources that it is not possible to use channels in wasm. Can you please confirm that it is an issue or share an example how it is possible to fetch using channels?

emilk commented 1 year ago

You can use channels, you just can't block on them. Use try_recv instead.