Skip to content

Commit ef4b86c

Browse files
committed
move the meat of futures-time underneath wstd::time
commenting out everything having to do with channels / park, temporarily no more prelude and tests are broken
1 parent a6ee46a commit ef4b86c

27 files changed

+97
-210
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ authors = [
1515
[features]
1616

1717
[dependencies]
18+
futures-core.workspace = true
1819
http.workspace = true
20+
pin-project-lite.workspace = true
1921
slab.workspace = true
2022
wasi.workspace = true
2123
wstd-macro.workspace = true
@@ -46,8 +48,10 @@ repository = "https://github.com/yoshuawuyts/wstd"
4648
[workspace.dependencies]
4749
anyhow = "1"
4850
cargo_metadata = "0.18.1"
51+
futures-core = "0.3.19"
4952
heck = "0.5"
5053
http = "1.1"
54+
pin-project-lite = "0.2.8"
5155
quote = "1.0"
5256
serde_json = "1"
5357
slab = "0.4.9"

futures-time/src/future/into_future.rs

Lines changed: 0 additions & 72 deletions
This file was deleted.

futures-time/src/time/mod.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

futures-time/src/time/duration.rs renamed to src/time/duration.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use crate::{
2-
future::IntoFuture,
1+
use super::{
32
stream::{Interval, IntoStream},
43
task::Sleep,
4+
Instant,
55
};
6-
6+
use std::future::IntoFuture;
77
use std::ops::{Add, AddAssign, Sub, SubAssign};
8-
9-
use super::Instant;
8+
use wasi::clocks::monotonic_clock;
109

1110
/// A Duration type to represent a span of time, typically used for system
1211
/// timeouts.
@@ -15,7 +14,7 @@ use super::Instant;
1514
/// without coherence issues, just like if we were implementing this in the
1615
/// stdlib.
1716
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone, Copy)]
18-
pub struct Duration(pub(crate) std::time::Duration);
17+
pub struct Duration(pub(crate) monotonic_clock::Duration);
1918
impl Duration {
2019
/// Creates a new `Duration` from the specified number of whole seconds and
2120
/// additional nanoseconds.
@@ -78,7 +77,7 @@ impl Duration {
7877
}
7978

8079
impl std::ops::Deref for Duration {
81-
type Target = std::time::Duration;
80+
type Target = monotonic_clock::Duration;
8281

8382
fn deref(&self) -> &Self::Target {
8483
&self.0
@@ -93,41 +92,46 @@ impl std::ops::DerefMut for Duration {
9392

9493
impl From<std::time::Duration> for Duration {
9594
fn from(inner: std::time::Duration) -> Self {
96-
Self(inner)
95+
Self(
96+
inner
97+
.as_nanos()
98+
.try_into()
99+
.expect("only dealing with durations that can fit in u64"),
100+
)
97101
}
98102
}
99103

100104
impl Into<std::time::Duration> for Duration {
101105
fn into(self) -> std::time::Duration {
102-
self.0
106+
std::time::Duration::from_nanos(self.0)
103107
}
104108
}
105109

106110
impl Add<Duration> for Duration {
107111
type Output = Self;
108112

109113
fn add(self, rhs: Duration) -> Self::Output {
110-
(self.0 + rhs.0).into()
114+
Self(self.0 + rhs.0)
111115
}
112116
}
113117

114118
impl AddAssign<Duration> for Duration {
115119
fn add_assign(&mut self, rhs: Duration) {
116-
*self = (self.0 + rhs.0).into()
120+
*self = Self(self.0 + rhs.0)
117121
}
118122
}
119123

120124
impl Sub<Duration> for Duration {
121125
type Output = Self;
122126

123127
fn sub(self, rhs: Duration) -> Self::Output {
124-
(self.0 - rhs.0).into()
128+
Self(self.0 - rhs.0)
125129
}
126130
}
127131

128132
impl SubAssign<Duration> for Duration {
129133
fn sub_assign(&mut self, rhs: Duration) {
130-
*self = (self.0 - rhs.0).into()
134+
*self = Self(self.0 - rhs.0)
131135
}
132136
}
133137

@@ -137,7 +141,7 @@ impl IntoFuture for Duration {
137141
type IntoFuture = Sleep;
138142

139143
fn into_future(self) -> Self::IntoFuture {
140-
crate::task::sleep(self)
144+
super::task::sleep(self)
141145
}
142146
}
143147

@@ -147,6 +151,6 @@ impl IntoStream for Duration {
147151
type IntoStream = Interval;
148152

149153
fn into_stream(self) -> Self::IntoStream {
150-
crate::stream::interval(self)
154+
super::stream::interval(self)
151155
}
152156
}
File renamed without changes.

futures-time/src/future/future_ext.rs renamed to src/time/future/future_ext.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use core::future::Future;
22

3-
use crate::channel::Parker;
4-
use crate::stream::IntoStream;
3+
//use crate::channel::Parker;
4+
//use crate::time::stream::IntoStream;
55

6-
use super::{Delay, IntoFuture, Park, Timeout};
6+
use super::{Delay, IntoFuture, Timeout};
77

88
/// Extend `Future` with time-based operations.
99
pub trait FutureExt: Future {
@@ -77,20 +77,21 @@ pub trait FutureExt: Future {
7777
{
7878
Delay::new(self, deadline.into_future())
7979
}
80-
81-
/// Suspend or resume execution of a future.
82-
///
83-
/// When this method is called the execution of the future will be put into
84-
/// a suspended state until the channel returns `Parker::Unpark` or the
85-
/// channel's senders are dropped. The underlying future will not be polled
86-
/// while the it is paused.
87-
fn park<I>(self, interval: I) -> Park<Self, I::IntoStream>
88-
where
89-
Self: Sized,
90-
I: IntoStream<Item = Parker>,
91-
{
92-
Park::new(self, interval.into_stream())
93-
}
80+
/* FIXME channels
81+
/// Suspend or resume execution of a future.
82+
///
83+
/// When this method is called the execution of the future will be put into
84+
/// a suspended state until the channel returns `Parker::Unpark` or the
85+
/// channel's senders are dropped. The underlying future will not be polled
86+
/// while the it is paused.
87+
fn park<I>(self, interval: I) -> Park<Self, I::IntoStream>
88+
where
89+
Self: Sized,
90+
I: IntoStream<Item = Parker>,
91+
{
92+
Park::new(self, interval.into_stream())
93+
}
94+
*/
9495
}
9596

9697
impl<T> FutureExt for T where T: Future {}

futures-time/src/future/mod.rs renamed to src/time/future/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141
4242
mod delay;
4343
mod future_ext;
44-
mod into_future;
45-
mod park;
44+
//mod park;
4645
mod relative_future;
4746
mod timeout;
4847

4948
pub use delay::Delay;
5049
pub use future_ext::FutureExt;
51-
pub use into_future::IntoFuture;
52-
pub use park::Park;
50+
//pub use park::Park;
5351
pub use relative_future::Timer;
52+
pub use std::future::IntoFuture;
5453
pub use timeout::Timeout;
File renamed without changes.

futures-time/src/future/timeout.rs renamed to src/time/future/timeout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::timeout_err;
1+
use crate::time::utils::timeout_err;
22

33
use std::future::Future;
44
use std::io;

0 commit comments

Comments
 (0)