Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Commit 2e6290c

Browse files
committed
Update for futures v0.3.0-alpha.15
Replace (most) usage of FutureObj with BoxFuture and use BoxFuture to simplify some function signatures. Enable the async-await feature for the tests.
1 parent 2d5af87 commit 2e6290c

File tree

9 files changed

+27
-37
lines changed

9 files changed

+27
-37
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency"
1313
edition = "2018"
1414

1515
[dependencies]
16-
futures-preview = { version = "0.3.0-alpha.14" }
16+
futures-preview = { version = "0.3.0-alpha.15" }
1717
runtime-attributes = { path = "runtime-attributes", version = "0.3.0-alpha.2" }
1818
runtime-raw = { path = "runtime-raw", version = "0.3.0-alpha.1" }
1919
runtime-native = { path = "runtime-native", version = "0.3.0-alpha.1" }
2020

2121
[dev-dependencies]
2222
failure = "0.1.5"
2323
futures01 = { package = "futures", version = "0.1" }
24+
futures-preview = { version = "0.3.0-alpha.15", features = ["nightly", "async-await"] }
2425
juliex = "0.3.0-alpha.2"
2526
mio = "0.6.16"
2627
rand = "0.6.5"

runtime-native/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2018"
1414

1515
[dependencies]
1616
async-datagram = "2.0.0"
17-
futures-preview = "0.3.0-alpha.13"
17+
futures-preview = "0.3.0-alpha.15"
1818
lazy_static = "1.0.0"
1919
romio = "0.3.0-alpha.5"
2020
runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.1" }

runtime-native/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
)]
1212

1313
use futures::prelude::*;
14-
use futures::{future::FutureObj, task::SpawnError};
14+
use futures::{future::BoxFuture, task::SpawnError};
1515
use lazy_static::lazy_static;
1616

17-
use std::future::Future;
1817
use std::io;
1918
use std::net::SocketAddr;
2019
use std::pin::Pin;
@@ -38,23 +37,22 @@ lazy_static! {
3837
pub struct Native;
3938

4039
impl runtime_raw::Runtime for Native {
41-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError> {
42-
JULIEX_THREADPOOL.spawn(fut);
40+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> {
41+
JULIEX_THREADPOOL.spawn_obj(fut.into());
4342
Ok(())
4443
}
4544

4645
fn connect_tcp_stream(
4746
&self,
4847
addr: &SocketAddr,
49-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>
50-
{
48+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> {
5149
let romio_connect = romio::TcpStream::connect(addr);
5250
let connect = romio_connect.map(|res| {
5351
res.map(|romio_stream| {
5452
Box::pin(TcpStream { romio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
5553
})
5654
});
57-
Box::pin(connect)
55+
connect.boxed()
5856
}
5957

6058
fn bind_tcp_listener(

runtime-raw/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency"
1313
edition = "2018"
1414

1515
[dependencies]
16-
futures-preview = "0.3.0-alpha.13"
16+
futures-preview = "0.3.0-alpha.15"

runtime-raw/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)]
1616

1717
use futures::executor;
18-
use futures::future::FutureObj;
18+
use futures::future::BoxFuture;
1919
use futures::prelude::*;
2020
use futures::task::SpawnError;
2121

@@ -65,16 +65,15 @@ where
6565
let _ = tx.send(t);
6666
};
6767

68-
rt.spawn_obj(FutureObj::from(Box::new(fut)))
69-
.expect("cannot spawn a future");
68+
rt.spawn_boxed(fut.boxed()).expect("cannot spawn a future");
7069

7170
executor::block_on(rx).expect("the main future has panicked")
7271
}
7372

7473
/// The runtime trait.
7574
pub trait Runtime: Send + Sync + 'static {
7675
/// Spawn a new future.
77-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError>;
76+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError>;
7877

7978
/// Create a new `TcpStream`.
8079
///
@@ -83,7 +82,7 @@ pub trait Runtime: Send + Sync + 'static {
8382
fn connect_tcp_stream(
8483
&self,
8584
addr: &SocketAddr,
86-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn TcpStream>>>> + Send>>;
85+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn TcpStream>>>>;
8786

8887
/// Create a new `TcpListener`.
8988
///

runtime-tokio/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency"
1313
edition = "2018"
1414

1515
[dependencies]
16-
futures-preview = { version = "0.3.0-alpha.13", features = ["compat", "io-compat"] }
16+
futures-preview = { version = "0.3.0-alpha.15", features = ["compat", "io-compat"] }
1717
futures01 = { package = "futures", version = "0.1" }
1818
lazy_static = "1.0.0"
1919
mio = "0.6.16"

runtime-tokio/src/lib.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
)]
1212

1313
use futures::{
14-
compat::Compat,
15-
future::{Future, FutureExt, FutureObj},
14+
compat::Future01CompatExt,
15+
future::{BoxFuture, FutureExt, TryFutureExt},
1616
task::SpawnError,
1717
};
1818
use lazy_static::lazy_static;
@@ -34,7 +34,7 @@ use udp::UdpSocket;
3434
pub struct Tokio;
3535

3636
impl runtime_raw::Runtime for Tokio {
37-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError> {
37+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> {
3838
lazy_static! {
3939
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = {
4040
tokio::runtime::Builder::new()
@@ -46,25 +46,21 @@ impl runtime_raw::Runtime for Tokio {
4646
};
4747
}
4848

49-
TOKIO_RUNTIME
50-
.executor()
51-
.spawn(Compat::new(fut.map(|_| Ok(()))));
49+
TOKIO_RUNTIME.executor().spawn(fut.unit_error().compat());
5250
Ok(())
5351
}
5452

5553
fn connect_tcp_stream(
5654
&self,
5755
addr: &SocketAddr,
58-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>
59-
{
60-
use futures::compat::Compat01As03;
56+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> {
6157
use futures01::Future;
6258

6359
let tokio_connect = tokio::net::TcpStream::connect(addr);
6460
let connect = tokio_connect.map(|tokio_stream| {
6561
Box::pin(TcpStream { tokio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
6662
});
67-
Box::pin(Compat01As03::new(connect))
63+
connect.compat().boxed()
6864
}
6965

7066
fn bind_tcp_listener(
@@ -89,7 +85,7 @@ impl runtime_raw::Runtime for Tokio {
8985
pub struct TokioCurrentThread;
9086

9187
impl runtime_raw::Runtime for TokioCurrentThread {
92-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError> {
88+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> {
9389
lazy_static! {
9490
static ref TOKIO_RUNTIME: Mutex<tokio::runtime::current_thread::Handle> = {
9591
let (tx, rx) = mpsc::channel();
@@ -114,24 +110,22 @@ impl runtime_raw::Runtime for TokioCurrentThread {
114110
TOKIO_RUNTIME
115111
.lock()
116112
.unwrap()
117-
.spawn(Compat::new(fut.map(|_| Ok(()))))
113+
.spawn(fut.unit_error().compat())
118114
.unwrap();
119115
Ok(())
120116
}
121117

122118
fn connect_tcp_stream(
123119
&self,
124120
addr: &SocketAddr,
125-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>
126-
{
127-
use futures::compat::Compat01As03;
121+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> {
128122
use futures01::Future;
129123

130124
let tokio_connect = tokio::net::TcpStream::connect(addr);
131125
let connect = tokio_connect.map(|tokio_stream| {
132126
Box::pin(TcpStream { tokio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
133127
});
134-
Box::pin(Compat01As03::new(connect))
128+
connect.compat().boxed()
135129
}
136130

137131
fn bind_tcp_listener(

src/net/tcp.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::io;
2121
use std::net::{SocketAddr, ToSocketAddrs};
2222
use std::pin::Pin;
2323

24+
use futures::future::BoxFuture;
2425
use futures::io::*;
2526
use futures::prelude::*;
2627
use futures::ready;
@@ -219,9 +220,7 @@ impl AsyncWrite for TcpStream {
219220
pub struct Connect {
220221
addrs: Option<io::Result<VecDeque<SocketAddr>>>,
221222
last_err: Option<io::Error>,
222-
future: Option<
223-
Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>,
224-
>,
223+
future: Option<BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>>>,
225224
runtime: &'static dyn runtime_raw::Runtime,
226225
}
227226

src/task.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::pin::Pin;
44

5-
use futures::future::FutureObj;
65
use futures::prelude::*;
76
use futures::task::{Context, Poll};
87

@@ -37,7 +36,7 @@ where
3736
};
3837

3938
runtime_raw::current_runtime()
40-
.spawn_obj(FutureObj::from(Box::new(fut)))
39+
.spawn_boxed(fut.boxed())
4140
.expect("cannot spawn a future");
4241

4342
JoinHandle { rx }

0 commit comments

Comments
 (0)