mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 01:01:34 +00:00
Default all async support to std::future
(#1741)
This commit defaults all crates in-tree to use `std::future` by default and none of them support the crates.io `futures` 0.1 crate any more. This is a breaking change for `wasm-bindgen-futures` and `wasm-bindgen-test` so they've both received a major version bump to reflect the new defaults. Historical versions of these crates should continue to work if necessary, but they won't receive any more maintenance after this is merged. The movement here liberally uses `async`/`await` to remove the need for using any combinators on the `Future` trait. As a result many of the crates now rely on a much more recent version of the compiler, especially to run tests. The `wasm-bindgen-futures` crate was updated to remove all of its futures-related dependencies and purely use `std::future`, hopefully improving its compatibility by not having any version compat considerations over time. The implementations of the executors here are relatively simple and only delve slightly into the `RawWaker` business since there are no other stable APIs in `std::task` for wrapping these. This commit also adds support for: #[wasm_bindgen_test] async fn foo() { // ... } where previously you needed to pass `(async)` now that's inferred because it's an `async fn`. Closes #1558 Closes #1695
This commit is contained in:
@ -1,28 +1,23 @@
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate js_sys;
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen_futures;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::prelude::*;
|
||||
use js_sys::Promise;
|
||||
use std::task::{Poll, Context};
|
||||
use std::pin::Pin;
|
||||
use std::time::Duration;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use std::future::Future;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
|
||||
pub struct Timeout {
|
||||
id: u32,
|
||||
id: JsValue,
|
||||
inner: JsFuture,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = setTimeout)]
|
||||
fn set_timeout(closure: JsValue, millis: f64) -> u32;
|
||||
fn set_timeout(closure: JsValue, millis: f64) -> JsValue;
|
||||
|
||||
#[wasm_bindgen(js_name = clearTimeout)]
|
||||
fn clear_timeout(id: u32);
|
||||
fn clear_timeout(id: &JsValue);
|
||||
}
|
||||
|
||||
impl Timeout {
|
||||
@ -47,17 +42,15 @@ impl Timeout {
|
||||
}
|
||||
|
||||
impl Future for Timeout {
|
||||
type Item = ();
|
||||
type Error = JsValue;
|
||||
type Output = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<(), JsValue> {
|
||||
let _obj = try_ready!(self.inner.poll());
|
||||
Ok(().into())
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<()> {
|
||||
Pin::new(&mut self.inner).poll(cx).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Timeout {
|
||||
fn drop(&mut self) {
|
||||
clear_timeout(self.id);
|
||||
clear_timeout(&self.id);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user