use tracing::error;
#[cfg(not(target_arch = "wasm32"))]
mod native;
#[cfg(target_arch = "wasm32")]
mod wasm;
use crate::{BoundedFuture, ResponseHandler, UiCallBack, ValidReturn};
#[cfg(not(target_arch = "wasm32"))]
pub use native::*;
#[cfg(target_arch = "wasm32")]
pub use wasm::*;
#[must_use = "receiver is needed to get the response"]
pub fn fetch_plus<FResponseHandler, FNotify, Fut, Ret>(
req: reqwest::RequestBuilder,
response_handler: FResponseHandler,
ui_notify: FNotify,
) -> crate::oneshot::Receiver<Ret>
where
FResponseHandler: ResponseHandler<Fut, Ret>,
Fut: BoundedFuture<Ret>,
Ret: ValidReturn,
FNotify: UiCallBack,
{
let (tx, rx) = crate::oneshot::channel();
let on_done = move |resp: reqwest::Result<reqwest::Response>| async {
let output = response_handler(resp).await;
match tx.send(output) {
Ok(()) => {}
Err(_output) => error!("failed to send output from handler"),
};
ui_notify();
};
fetch(req, on_done);
rx
}