-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from expenses/wasm-support
Support for `wasm32-unknown-unknown`
- Loading branch information
Showing
10 changed files
with
98 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! A version of `Delay` that works on wasm. | ||
|
||
use gloo_timers::future::TimeoutFuture; | ||
use send_wrapper::SendWrapper; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
time::Duration, | ||
}; | ||
|
||
/// A version of `Delay` that works on wasm. | ||
#[derive(Debug)] | ||
pub struct Delay(SendWrapper<TimeoutFuture>); | ||
|
||
impl Delay { | ||
/// Creates a new future which will fire at `dur` time into the future. | ||
#[inline] | ||
pub fn new(dur: Duration) -> Delay { | ||
Self(SendWrapper::new(TimeoutFuture::new(dur.as_millis() as u32))) | ||
} | ||
|
||
/// Resets the timeout. | ||
#[inline] | ||
pub fn reset(&mut self, dur: Duration) { | ||
*self = Delay::new(at); | ||
} | ||
} | ||
|
||
impl Future for Delay { | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { | ||
Pin::new(&mut *Pin::into_inner(self).0).poll(cx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters