Skip to content

Commit abf64b7

Browse files
committed
Support wasm
1 parent d47bc45 commit abf64b7

File tree

8 files changed

+16
-7
lines changed

8 files changed

+16
-7
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Timeouts for futures.
1414

1515
[dependencies]
1616

17+
[target.wasm32-unknown-unknown.dependencies]
18+
instant = { version = "0.1.2", features = ["wasm-bindgen"] }
19+
1720
[dev-dependencies]
1821
async-std = { version = "1.0.1", features = ["attributes"] }
1922
futures = "0.3.1"

src/delay.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use std::sync::atomic::AtomicUsize;
1010
use std::sync::atomic::Ordering::SeqCst;
1111
use std::sync::{Arc, Mutex};
1212
use std::task::{Context, Poll};
13-
use std::time::{Duration, Instant};
13+
use std::time::Duration;
14+
use crate::Instant;
1415

1516
use crate::arc_list::Node;
1617
use crate::AtomicWaker;

src/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
88
use std::thread;
99
use std::thread::Thread;
10-
use std::time::Instant;
10+
use crate::Instant;
1111

1212
use crate::{Timer, TimerHandle};
1313

src/heap_timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cmp::Ordering;
22
use std::sync::Arc;
3-
use std::time::Instant;
3+
use crate::Instant;
44

55
use crate::{Node, ScheduledTimer};
66

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ use heap_timer::HeapTimer;
3131
use timer::{ScheduledTimer, Timer, TimerHandle};
3232

3333
pub use self::delay::Delay;
34+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
35+
use instant::Instant;
36+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
37+
use std::time::Instant;

src/timer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::sync::atomic::AtomicUsize;
55
use std::sync::atomic::Ordering::SeqCst;
66
use std::sync::{Arc, Mutex, Weak};
77
use std::task::{Context, Poll};
8-
use std::time::Instant;
9-
8+
use crate::Instant;
109
use std::future::Future;
1110

1211
use crate::AtomicWaker;

tests/smoke.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::error::Error;
22
use std::pin::Pin;
3-
use std::time::{Duration, Instant};
3+
use std::time::Duration;
4+
use crate::Instant;
45

56
use futures_timer::Delay;
67

tests/timeout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::error::Error;
2-
use std::time::{Duration, Instant};
2+
use std::time::Duration;
3+
use crate::Instant;
34

45
use futures_timer::Delay;
56

0 commit comments

Comments
 (0)