Swap Handle/Pinned

* Handle -> Remote
* Pinned -> Handle

All APIs now take a `&Handle` by default and in general can return an immediate
`io::Result` instead of an `IoFuture`. This reflects how most usage will likely
be done through handles rather than remotes, and also all previous functionality
can be recovered with a `oneshot` plus `Remote::spawn`.

Closes #15
This commit is contained in:
Alex Crichton
2016-09-07 22:12:41 -07:00
parent e60002b653
commit 66cff8e84b
23 changed files with 327 additions and 1344 deletions
+1 -2
View File
@@ -25,8 +25,7 @@ fn echo_server() {
drop(env_logger::init());
let mut l = t!(Core::new());
let srv = TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let msg = "foo bar baz";
+1 -2
View File
@@ -21,8 +21,7 @@ macro_rules! t {
#[test]
fn chain_clients() {
let mut l = t!(Core::new());
let srv = TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let t = thread::spawn(move || {
+1 -2
View File
@@ -24,8 +24,7 @@ fn echo_server() {
drop(env_logger::init());
let mut l = t!(Core::new());
let srv = TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let msg = "foo bar baz";
+1 -2
View File
@@ -21,8 +21,7 @@ macro_rules! t {
#[test]
fn limit() {
let mut l = t!(Core::new());
let srv = TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let t = thread::spawn(move || {
+5 -5
View File
@@ -12,11 +12,11 @@ fn simple() {
let (tx1, rx1) = futures::oneshot();
let (tx2, rx2) = futures::oneshot();
lp.pin().spawn(futures::lazy(|| {
lp.handle().spawn(futures::lazy(|| {
tx1.complete(1);
Ok(())
}));
lp.handle().spawn(|_| {
lp.remote().spawn(|_| {
futures::lazy(|| {
tx2.complete(2);
Ok(())
@@ -33,10 +33,10 @@ fn spawn_in_poll() {
let (tx1, rx1) = futures::oneshot();
let (tx2, rx2) = futures::oneshot();
let handle = lp.handle();
lp.pin().spawn(futures::lazy(move || {
let remote = lp.remote();
lp.handle().spawn(futures::lazy(move || {
tx1.complete(1);
handle.spawn(|_| {
remote.spawn(|_| {
futures::lazy(|| {
tx2.complete(2);
Ok(())
+1 -2
View File
@@ -24,8 +24,7 @@ fn echo_server() {
drop(env_logger::init());
let mut l = t!(Core::new());
let srv = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let t = thread::spawn(move || {
+2 -4
View File
@@ -40,8 +40,7 @@ fn connect() {
fn accept() {
drop(env_logger::init());
let mut l = t!(Core::new());
let srv = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let (tx, rx) = channel();
@@ -66,8 +65,7 @@ fn accept() {
fn accept2() {
drop(env_logger::init());
let mut l = t!(Core::new());
let srv = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &l.handle());
let srv = t!(l.run(srv));
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let addr = t!(srv.local_addr());
let t = thread::spawn(move || {
+1 -2
View File
@@ -4,7 +4,6 @@ extern crate tokio_core;
use std::time::{Instant, Duration};
use futures::Future;
use tokio_core::reactor::{Core, Timeout};
macro_rules! t {
@@ -19,7 +18,7 @@ fn smoke() {
drop(env_logger::init());
let mut l = t!(Core::new());
let dur = Duration::from_millis(10);
let timeout = Timeout::new(dur, &l.handle()).and_then(|t| t);
let timeout = t!(Timeout::new(dur, &l.handle()));
let start = Instant::now();
t!(l.run(timeout));
assert!(start.elapsed() >= dur);
+2 -3
View File
@@ -19,9 +19,8 @@ macro_rules! t {
#[test]
fn send_messages() {
let mut l = t!(Core::new());
let a = UdpSocket::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let b = UdpSocket::bind(&t!("127.0.0.1:0".parse()), &l.handle());
let (a, b) = t!(l.run(a.join(b)));
let a = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let b = t!(UdpSocket::bind(&t!("127.0.0.1:0".parse()), &l.handle()));
let a_addr = t!(a.local_addr());
let b_addr = t!(b.local_addr());