Skip to content

Commit 5ced38b

Browse files
committed
Add send_wrapper
1 parent 2250577 commit 5ced38b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Timeouts for futures.
1414

1515
[dependencies]
1616
gloo-timers = { version = "0.2.0", features = ["futures"], optional = true }
17+
send_wrapper = { version = "0.4.0", optional = true }
1718

1819
[dev-dependencies]
1920
async-std = { version = "1.0.1", features = ["attributes"] }
2021
futures = "0.3.1"
2122

2223
[features]
2324
wasm-bindgen = [
24-
"gloo-timers"
25+
"gloo-timers",
26+
"send_wrapper"
2527
]

src/delay_wasm.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
//! A version of `Delay` that works on wasm.
22
33
use gloo_timers::future::TimeoutFuture;
4+
use send_wrapper::SendWrapper;
45
use std::{time::Duration, pin::Pin, task::{Context, Poll}, future::Future};
56

67
/// A version of `Delay` that works on wasm.
78
#[derive(Debug)]
8-
pub struct Delay(TimeoutFuture);
9+
pub struct Delay(SendWrapper<TimeoutFuture>);
910

1011
impl Delay {
1112
/// Creates a new future which will fire at `dur` time into the future.
1213
#[inline]
1314
pub fn new(dur: Duration) -> Delay {
14-
Self(TimeoutFuture::new(dur.as_millis() as u32))
15+
Self(
16+
SendWrapper::new(TimeoutFuture::new(dur.as_millis() as u32))
17+
)
1518
}
1619
}
1720

1821
impl Future for Delay {
1922
type Output = ();
2023

2124
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
22-
Pin::new(&mut Pin::into_inner(self).0).poll(cx)
25+
Pin::new(&mut *Pin::into_inner(self).0).poll(cx)
2326
}
2427
}

0 commit comments

Comments
 (0)