Comments (1)
To make it portable between web and native you need to do something like this:
#[cfg(not(target_arch = "wasm32"))]
fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) {
std::thread::spawn(move || {
std::thread::sleep(delay);
f();
});
}
#[cfg(target_arch = "wasm32")]
fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) {
use wasm_bindgen::prelude::*;
let window = web_sys::window().unwrap();
let closure = Closure::once(f);
let delay_ms = delay.as_millis() as _;
window
.set_timeout_with_callback_and_timeout_and_arguments_0(
closure.as_ref().unchecked_ref(),
delay_ms,
)
.unwrap();
closure.forget(); // We must forget it, or else the callback is canceled on drop
}
from ehttp.
Related Issues (20)
- Documentation for HTTPS Request with cookie? HOT 4
- Hello, is there a way to proxify the requests ? HOT 2
- Demo Ehttp on Mobile: JsValue Error. Failed to fetch. HOT 3
- Ignoring TLS cert expiration HOT 1
- Fetching using channels HOT 1
- Old version of rust specified HOT 2
- Support for nodejs HOT 7
- Blocking untill the end of the response? HOT 8
- 0.3.1 tag is missing HOT 1
- Headers need same key
- Keep `ureq::Agent` for native clients HOT 1
- ehttp is not passing the `console` feature to `web-sys` HOT 1
- Windows Defender on Windows 10 thinks cross-compiled example_eframe is malware HOT 1
- Build fails with vendored dependencies HOT 1
- Allow configuration of `RequestMode` on wasm HOT 2
- Conditional Compile Required for Requests
- Missing documentation for Request mode field
- Headers field unused on WASM HOT 1
- Failed when using ehttp in web worker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ehttp.