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

Commit a0503eb

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.
1 parent 2d5af87 commit a0503eb

File tree

9 files changed

+26
-31
lines changed

9 files changed

+26
-31
lines changed

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.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" }

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-6
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,23 @@ 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>>
48+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>>
5049
{
5150
let romio_connect = romio::TcpStream::connect(addr);
5251
let connect = romio_connect.map(|res| {
5352
res.map(|romio_stream| {
5453
Box::pin(TcpStream { romio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
5554
})
5655
});
57-
Box::pin(connect)
56+
connect.boxed()
5857
}
5958

6059
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-4
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,7 +65,7 @@ where
6565
let _ = tx.send(t);
6666
};
6767

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

7171
executor::block_on(rx).expect("the main future has panicked")
@@ -74,7 +74,7 @@ where
7474
/// The runtime trait.
7575
pub trait Runtime: Send + Sync + 'static {
7676
/// Spawn a new future.
77-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError>;
77+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError>;
7878

7979
/// Create a new `TcpStream`.
8080
///
@@ -83,7 +83,7 @@ pub trait Runtime: Send + Sync + 'static {
8383
fn connect_tcp_stream(
8484
&self,
8585
addr: &SocketAddr,
86-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn TcpStream>>>> + Send>>;
86+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn TcpStream>>>>;
8787

8888
/// Create a new `TcpListener`.
8989
///

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-12
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+
future::{FutureExt, BoxFuture, TryFutureExt},
15+
compat::{Future01CompatExt},
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()
@@ -48,23 +48,22 @@ impl runtime_raw::Runtime for Tokio {
4848

4949
TOKIO_RUNTIME
5050
.executor()
51-
.spawn(Compat::new(fut.map(|_| Ok(()))));
51+
.spawn(fut.unit_error().compat());
5252
Ok(())
5353
}
5454

5555
fn connect_tcp_stream(
5656
&self,
5757
addr: &SocketAddr,
58-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>
58+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>>
5959
{
60-
use futures::compat::Compat01As03;
6160
use futures01::Future;
6261

6362
let tokio_connect = tokio::net::TcpStream::connect(addr);
6463
let connect = tokio_connect.map(|tokio_stream| {
6564
Box::pin(TcpStream { tokio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
6665
});
67-
Box::pin(Compat01As03::new(connect))
66+
connect.compat().boxed()
6867
}
6968

7069
fn bind_tcp_listener(
@@ -89,7 +88,7 @@ impl runtime_raw::Runtime for Tokio {
8988
pub struct TokioCurrentThread;
9089

9190
impl runtime_raw::Runtime for TokioCurrentThread {
92-
fn spawn_obj(&self, fut: FutureObj<'static, ()>) -> Result<(), SpawnError> {
91+
fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> {
9392
lazy_static! {
9493
static ref TOKIO_RUNTIME: Mutex<tokio::runtime::current_thread::Handle> = {
9594
let (tx, rx) = mpsc::channel();
@@ -114,24 +113,23 @@ impl runtime_raw::Runtime for TokioCurrentThread {
114113
TOKIO_RUNTIME
115114
.lock()
116115
.unwrap()
117-
.spawn(Compat::new(fut.map(|_| Ok(()))))
116+
.spawn(fut.unit_error().compat())
118117
.unwrap();
119118
Ok(())
120119
}
121120

122121
fn connect_tcp_stream(
123122
&self,
124123
addr: &SocketAddr,
125-
) -> Pin<Box<dyn Future<Output = io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> + Send>>
124+
) -> BoxFuture<'static, io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>>
126125
{
127-
use futures::compat::Compat01As03;
128126
use futures01::Future;
129127

130128
let tokio_connect = tokio::net::TcpStream::connect(addr);
131129
let connect = tokio_connect.map(|tokio_stream| {
132130
Box::pin(TcpStream { tokio_stream }) as Pin<Box<dyn runtime_raw::TcpStream>>
133131
});
134-
Box::pin(Compat01As03::new(connect))
132+
connect.compat().boxed()
135133
}
136134

137135
fn bind_tcp_listener(

src/net/tcp.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::pin::Pin;
2424
use futures::io::*;
2525
use futures::prelude::*;
2626
use futures::ready;
27+
use futures::future::BoxFuture;
2728
use futures::task::{Context, Poll};
2829

2930
/// A TCP stream between a local and a remote socket.
@@ -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)