Skip to content

Commit 95b2221

Browse files
authored
Merge pull request #134 from freedomlayer/real/fix/remove-future-obj
Remove usage of FutureObj
2 parents c999e1e + d214289 commit 95b2221

File tree

17 files changed

+255
-193
lines changed

17 files changed

+255
-193
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ matrix:
1212
include:
1313
- env: TARGET=x86_64-unknown-linux-gnu CC=gcc-6 CXX=g++-6 KCOV=1
1414
os: linux
15-
rust: nightly-2018-11-13
15+
rust: nightly-2018-11-27
1616
before_script:
1717
- travis/trusty/before-script.sh
1818
addons:
@@ -29,7 +29,7 @@ matrix:
2929

3030
- env: TARGET=x86_64-apple-darwin KCOV=0
3131
os: osx
32-
rust: nightly-2018-11-13
32+
rust: nightly-2018-11-27
3333
osx_image: xcode9.2
3434
before_script:
3535
- brew install capnp

Cargo.lock

Lines changed: 200 additions & 137 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/channeler/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["rename-dependency"]
2-
31
[package]
42
name = "offst-channeler"
53
version = "0.1.0"
@@ -18,5 +16,6 @@ relay = { path = "../relay", version = "0.1.0" , package = "offst-relay" }
1816
secure_channel = { path = "../secure_channel", version = "0.1.0" , package = "offst-secure-channel" }
1917

2018
log = "0.4"
21-
futures-preview = "0.3.0-alpha.9"
19+
# futures-preview = "0.3.0-alpha.9"
20+
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "5d87cce202" }
2221

components/channeler/src/connector_utils.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use futures::future::FutureObj;
2-
use futures::FutureExt;
1+
use core::pin::Pin;
2+
3+
use futures::{Future, FutureExt};
34
use futures::task::Spawn;
45
use futures::future;
56

@@ -37,8 +38,8 @@ where
3738
type SendItem = C::SendItem;
3839
type RecvItem = C::RecvItem;
3940

40-
fn connect(&mut self, address: ())
41-
-> FutureObj<Option<ConnPair<C::SendItem, C::RecvItem>>> {
41+
fn connect<'a>(&'a mut self, address: ())
42+
-> Pin<Box<dyn Future<Output=Option<ConnPair<C::SendItem, C::RecvItem>>> + Send + 'a>> {
4243
self.connector.connect(self.address.clone())
4344
}
4445
}
@@ -88,8 +89,8 @@ where
8889
type SendItem = Vec<u8>;
8990
type RecvItem = Vec<u8>;
9091

91-
fn connect(&mut self, full_address: (PublicKey, A))
92-
-> FutureObj<Option<ConnPair<Vec<u8>, Vec<u8>>>> {
92+
fn connect<'a>(&'a mut self, full_address: (PublicKey, A))
93+
-> Pin<Box<dyn Future<Output=Option<ConnPair<C::SendItem, C::RecvItem>>> + Send + 'a>> {
9394

9495
let (public_key, address) = full_address;
9596
let fut = async move {
@@ -108,6 +109,6 @@ where
108109
receiver: secure_channel.receiver,
109110
})
110111
};
111-
FutureObj::new(fut.boxed())
112+
Box::pinned(fut)
112113
}
113114
}

components/channeler/src/listener.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::marker::Unpin;
2-
use futures::{select, future, Stream, StreamExt, Sink};
2+
use futures::{select, future, FutureExt, Stream, StreamExt, Sink};
33
use futures::task::Spawn;
44

55
use proto::funder::messages::{FunderToChanneler, ChannelerToFunder};
@@ -100,20 +100,20 @@ where
100100
// TODO: Possibly wait here in a smart way? Exponential backoff?
101101
await!(sleep_ticks(backoff_ticks, timer_client.clone()))?;
102102
Ok(())
103-
});
103+
}).fuse();
104104

105105
// TODO: Get rid of Box::pinned() later.
106106
let mut new_address_fut = Box::pinned(async {
107107
match await!(incoming_addresses.next()) {
108108
Some(address) => ListenerSelect::IncomingAddress(address),
109109
None => ListenerSelect::IncomingAddressClosed,
110110
}
111-
});
111+
}).fuse();
112112

113113
// TODO: Could we possibly lose an incoming address with this select?
114114
let listener_select = select! {
115-
listener_fut => ListenerSelect::ListenerError(listener_fut.err().unwrap()),
116-
new_address_fut => new_address_fut,
115+
listener_fut = listener_fut => ListenerSelect::ListenerError(listener_fut.err().unwrap()),
116+
new_address_fut = new_address_fut => new_address_fut,
117117
};
118118
// TODO: Make code nicer here somehow. Use scopes instead of drop?
119119
drop(new_address_fut);

components/funder/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["rename-dependency"]
2-
31
[package]
42
name = "offst-funder"
53
version = "0.1.0"
@@ -27,7 +25,8 @@ bytes = "0.4"
2725
# tokio-codec = "0.1"
2826
# futures-await = "0.1"
2927
futures-cpupool = "0.1.8"
30-
futures-preview = "0.3.0-alpha.9"
28+
# futures-preview = "0.3.0-alpha.9"
29+
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "5d87cce202" }
3130

3231
num-bigint = "0.2.0"
3332
num-traits = "0.2.4"

components/identity/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["rename-dependency"]
2-
31
[package]
42
name = "offst-identity"
53
version = "0.1.0"
@@ -15,7 +13,8 @@ crypto = { path = "../crypto", version = "0.1.0" , package = "offst-crypto"}
1513
# futures = "0.1.25"
1614
# tokio-core = "0.1"
1715
# futures-await = "0.1"
18-
futures-preview = "0.3.0-alpha.9"
16+
# futures-preview = "0.3.0-alpha.9"
17+
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "5d87cce202" }
1918

2019
[dev-dependencies]
2120

components/relay/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["rename-dependency"]
2-
31
[package]
42
name = "offst-relay"
53
version = "0.1.0"
@@ -15,5 +13,6 @@ timer = { path = "../timer", version = "0.1.0" , package = "offst-timer" }
1513
proto = { path = "../proto", version = "0.1.0" , package = "offst-proto" }
1614

1715
log = "0.4"
18-
futures-preview = "0.3.0-alpha.9"
16+
# futures-preview = "0.3.0-alpha.9"
17+
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "5d87cce202" }
1918

components/relay/src/client/client_connector.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use core::pin::Pin;
12
use crypto::identity::PublicKey;
2-
use futures::{future, FutureExt, TryFutureExt, StreamExt, SinkExt};
3-
use futures::future::FutureObj;
3+
use futures::{future, Future, FutureExt, TryFutureExt, StreamExt, SinkExt};
44
use futures::task::{Spawn, SpawnExt};
55
use futures::channel::mpsc;
66

@@ -106,11 +106,13 @@ where
106106
type SendItem = Vec<u8>;
107107
type RecvItem = Vec<u8>;
108108

109-
fn connect(&mut self, address: (A, PublicKey)) -> FutureObj<Option<ConnPair<Self::SendItem, Self::RecvItem>>> {
109+
fn connect<'a>(&'a mut self, address: (A, PublicKey))
110+
-> Pin<Box<dyn Future<Output=Option<ConnPair<Self::SendItem, Self::RecvItem>>> + Send + 'a>> {
111+
110112
let (relay_address, remote_public_key) = address;
111113
let relay_connect = self.relay_connect(relay_address, remote_public_key)
112114
.map(|res| res.ok());
113-
FutureObj::new(relay_connect.boxed())
115+
Box::pinned(relay_connect)
114116
}
115117
}
116118

components/relay/src/client/client_listener.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ where
9595
let conn_timeout_ticks = usize_to_u64(conn_timeout_ticks).unwrap();
9696
let mut fut_timeout = timer_stream
9797
.take(conn_timeout_ticks)
98-
.for_each(|_| future::ready(()));
99-
let mut fut_connect = connector.connect(());
98+
.for_each(|_| future::ready(()))
99+
.fuse();
100+
let mut fut_connect = connector.connect(()).fuse();
100101

101102
select! {
102-
fut_timeout => None,
103-
fut_connect => fut_connect,
103+
fut_timeout = fut_timeout => None,
104+
fut_connect = fut_connect => fut_connect,
104105
}
105106
}
106107

@@ -507,7 +508,7 @@ mod tests {
507508
async fn task_client_listener_basic(mut spawner: impl Spawn + Clone + Send + 'static) {
508509
let (req_sender, mut req_receiver) = mpsc::channel(0);
509510
let connector = DummyConnector::new(req_sender);
510-
let (connections_sender, mut connections_receiver) = mpsc::channel(0);
511+
let (connections_sender, connections_receiver) = mpsc::channel(0);
511512
let conn_timeout_ticks = 8;
512513
let keepalive_ticks = 16;
513514
let (tick_sender, tick_receiver) = mpsc::channel(0);
@@ -587,7 +588,7 @@ mod tests {
587588
// Listener will accept the connection:
588589

589590
// Listener will open a connection to the relay:
590-
let (mut remote_sender, local_receiver) = mpsc::channel(0);
591+
let (remote_sender, local_receiver) = mpsc::channel(0);
591592
let (local_sender, mut remote_receiver) = mpsc::channel(0);
592593
let conn_pair = ConnPair {
593594
sender: local_sender,

0 commit comments

Comments
 (0)