threadpool: update to std::future (#1219)

An initial pass at updating `tokio-threadpool` to `std::future`. The
codebase and tests both now run using `std::future` but the wake
mechanism is not ideal. Follow up work will be required to improve on
this.

Refs: #1200
This commit is contained in:
Carl Lerche
2019-06-27 22:30:56 -07:00
committed by GitHub
parent e4415d986a
commit e7488d983e
17 changed files with 436 additions and 485 deletions
+15 -4
View File
@@ -2,8 +2,8 @@ use crate::builder::Builder;
use crate::pool::Pool;
use crate::sender::Sender;
use crate::shutdown::{Shutdown, ShutdownTrigger};
use futures::sync::oneshot;
use futures::{Future, Poll};
use std::future::Future;
use std::sync::Arc;
/// Work-stealing based thread pool for executing futures.
@@ -72,11 +72,14 @@ impl ThreadPool {
/// version that returns a `Result` instead of panicking.
pub fn spawn<F>(&self, future: F)
where
F: Future<Item = (), Error = ()> + Send + 'static,
F: Future<Output = ()> + Send + 'static,
{
self.sender().spawn(future).unwrap();
}
/*
* TODO: Bring back
/// Spawn a future on to the thread pool, return a future representing
/// the produced value.
///
@@ -114,6 +117,8 @@ impl ThreadPool {
SpawnHandle(oneshot::spawn(future, self.sender()))
}
*/
/// Return a reference to the sender handle
///
/// The handle is used to spawn futures onto the thread pool. It also
@@ -183,11 +188,15 @@ impl Drop for ThreadPool {
drop(inner);
// Wait until all worker threads terminate and the threadpool's resources clean up.
let _ = shutdown.wait();
let mut enter = tokio_executor::enter().unwrap();
enter.block_on(shutdown);
}
}
}
/*
* TODO: Bring back
/// Handle returned from ThreadPool::spawn_handle.
///
/// This handle is a future representing the completion of a different future
@@ -205,3 +214,5 @@ impl<T, E> Future for SpawnHandle<T, E> {
self.0.poll()
}
}
*/