emilk / ehttp

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

How to do callback in fetch function #2

Closed leafjolt closed 2 years ago

leafjolt commented 2 years ago

I wanted to use ehttp for a project of mine where I need to make a request (no use of async/await), get the response text from that request, and deserialize it with Serde. I am having some trouble finding a way to get the response value outside of the callback closure in the fetch function so I can pass the response text into Serde. Is there any way to do this?

emilk commented 2 years ago

Pass something like an Arc<Mutex<Response>> to the ehttp callback like in the example at https://github.com/emilk/ehttp/blob/master/example_eframe/src/lib.rs, or use std::sync::mpsc::channel to send it back