mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-06 00:00:10 +02:00
Migrate threadpool to futures-util (#1403)
* Migrate threadpool to futures-util Signed-off-by: Lucio Franco <[email protected]> * fmt
This commit is contained in:
@@ -25,7 +25,7 @@ publish = false
|
|||||||
async-traits = []
|
async-traits = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-util = { git = "https://github.com/tokio-rs/async" }
|
futures-util-preview = "= 0.3.0-alpha.17"
|
||||||
tokio-io = { version = "0.2.0", path = "../tokio-io" }
|
tokio-io = { version = "0.2.0", path = "../tokio-io" }
|
||||||
tokio-reactor = { version = "0.2.0", path = "../tokio-reactor" }
|
tokio-reactor = { version = "0.2.0", path = "../tokio-reactor" }
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
use super::incoming::Incoming;
|
use super::incoming::Incoming;
|
||||||
use super::TcpStream;
|
use super::TcpStream;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use futures_util::future::poll_fn;
|
||||||
use mio;
|
use mio;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@@ -87,7 +88,6 @@ impl TcpListener {
|
|||||||
/// ```
|
/// ```
|
||||||
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
||||||
pub async fn accept(&mut self) -> io::Result<(TcpStream, SocketAddr)> {
|
pub async fn accept(&mut self) -> io::Result<(TcpStream, SocketAddr)> {
|
||||||
use async_util::future::poll_fn;
|
|
||||||
poll_fn(|cx| self.poll_accept(cx)).await
|
poll_fn(|cx| self.poll_accept(cx)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ use crate::split::{
|
|||||||
split, split_mut, TcpStreamReadHalf, TcpStreamReadHalfMut, TcpStreamWriteHalf,
|
split, split_mut, TcpStreamReadHalf, TcpStreamReadHalfMut, TcpStreamWriteHalf,
|
||||||
TcpStreamWriteHalfMut,
|
TcpStreamWriteHalfMut,
|
||||||
};
|
};
|
||||||
use async_util::future::poll_fn;
|
|
||||||
use bytes::{Buf, BufMut};
|
use bytes::{Buf, BufMut};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use futures_util::future::poll_fn;
|
||||||
use iovec::IoVec;
|
use iovec::IoVec;
|
||||||
use mio;
|
use mio;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
tokio-executor = { version = "0.2.0", path = "../tokio-executor" }
|
tokio-executor = { version = "0.2.0", path = "../tokio-executor" }
|
||||||
tokio-sync = { version = "0.2.0", path = "../tokio-sync" }
|
tokio-sync = { version = "0.2.0", path = "../tokio-sync" }
|
||||||
futures-core-preview = "0.3.0-alpha.17"
|
futures-core-preview = "= 0.3.0-alpha.17"
|
||||||
|
futures-util-preview = "= 0.3.0-alpha.17"
|
||||||
|
|
||||||
arc-waker = { git = "https://github.com/tokio-rs/async" }
|
|
||||||
crossbeam-deque = "0.7.0"
|
crossbeam-deque = "0.7.0"
|
||||||
crossbeam-queue = "0.1.0"
|
crossbeam-queue = "0.1.0"
|
||||||
crossbeam-utils = "0.6.4"
|
crossbeam-utils = "0.6.4"
|
||||||
@@ -39,6 +39,6 @@ lazy_static = "1"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
env_logger = "0.5"
|
env_logger = "0.5"
|
||||||
async-util = { git = "https://github.com/tokio-rs/async" }
|
|
||||||
tokio = { version = "0.2.0", path = "../tokio" }
|
tokio = { version = "0.2.0", path = "../tokio" }
|
||||||
tokio-test = { version = "0.2.0", path = "../tokio-test" }
|
tokio-test = { version = "0.2.0", path = "../tokio-test" }
|
||||||
|
futures-util-preview = "= 0.3.0-alpha.17"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use self::state::State;
|
|||||||
use crate::pool::Pool;
|
use crate::pool::Pool;
|
||||||
use crate::waker::Waker;
|
use crate::waker::Waker;
|
||||||
|
|
||||||
|
use futures_util::task::ArcWake;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use std::cell::{Cell, UnsafeCell};
|
use std::cell::{Cell, UnsafeCell};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@@ -134,7 +135,7 @@ impl Task {
|
|||||||
|
|
||||||
let mut g = Guard(fut, true);
|
let mut g = Guard(fut, true);
|
||||||
|
|
||||||
let waker = arc_waker::waker(Arc::new(Waker {
|
let waker = ArcWake::into_waker(Arc::new(Waker {
|
||||||
task: me.clone(),
|
task: me.clone(),
|
||||||
pool: pool.clone(),
|
pool: pool.clone(),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::pool::Pool;
|
use crate::pool::Pool;
|
||||||
use crate::task::Task;
|
use crate::task::Task;
|
||||||
|
|
||||||
use arc_waker::Wake;
|
use futures_util::task::ArcWake;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Implements the future `Waker` API.
|
/// Implements the future `Waker` API.
|
||||||
@@ -17,7 +17,7 @@ pub(crate) struct Waker {
|
|||||||
unsafe impl Send for Waker {}
|
unsafe impl Send for Waker {}
|
||||||
unsafe impl Sync for Waker {}
|
unsafe impl Sync for Waker {}
|
||||||
|
|
||||||
impl Wake for Waker {
|
impl ArcWake for Waker {
|
||||||
fn wake_by_ref(me: &Arc<Self>) {
|
fn wake_by_ref(me: &Arc<Self>) {
|
||||||
Task::schedule(&me.task, &me.pool);
|
Task::schedule(&me.task, &me.pool);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
use tokio_test::*;
|
use tokio_test::*;
|
||||||
use tokio_threadpool::*;
|
use tokio_threadpool::*;
|
||||||
|
|
||||||
use async_util::future::poll_fn;
|
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use futures_util::future::poll_fn;
|
||||||
use rand::*;
|
use rand::*;
|
||||||
use std::sync::atomic::Ordering::*;
|
use std::sync::atomic::Ordering::*;
|
||||||
use std::sync::atomic::*;
|
use std::sync::atomic::*;
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ async-traits = []
|
|||||||
tokio-executor = { version = "0.2.0", path = "../tokio-executor" }
|
tokio-executor = { version = "0.2.0", path = "../tokio-executor" }
|
||||||
tokio-sync = { version = "0.2.0", path = "../tokio-sync" }
|
tokio-sync = { version = "0.2.0", path = "../tokio-sync" }
|
||||||
futures-core-preview = "0.3.0-alpha.17"
|
futures-core-preview = "0.3.0-alpha.17"
|
||||||
|
futures-util-preview = "0.3.0-alpha.17"
|
||||||
|
|
||||||
async-util = { git = "https://github.com/tokio-rs/async" }
|
|
||||||
crossbeam-utils = "0.6.0"
|
crossbeam-utils = "0.6.0"
|
||||||
# Backs `DelayQueue`
|
# Backs `DelayQueue`
|
||||||
slab = "0.4.1"
|
slab = "0.4.1"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::wheel::{self, Wheel};
|
|||||||
use crate::{Delay, Error};
|
use crate::{Delay, Error};
|
||||||
|
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use futures_util::future::poll_fn;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@@ -373,8 +374,6 @@ impl<T> DelayQueue<T> {
|
|||||||
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
||||||
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
||||||
pub async fn next(&mut self) -> Option<Result<Expired<T>, Error>> {
|
pub async fn next(&mut self) -> Option<Result<Expired<T>, Error>> {
|
||||||
use async_util::future::poll_fn;
|
|
||||||
|
|
||||||
poll_fn(|cx| self.poll_next(cx)).await
|
poll_fn(|cx| self.poll_next(cx)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::clock;
|
|||||||
use crate::Delay;
|
use crate::Delay;
|
||||||
|
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use futures_util::future::poll_fn;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{self, Poll};
|
use std::task::{self, Poll};
|
||||||
@@ -75,8 +76,6 @@ impl Interval {
|
|||||||
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
|
||||||
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
#[allow(clippy::should_implement_trait)] // false positive : https://github.com/rust-lang/rust-clippy/issues/4290
|
||||||
pub async fn next(&mut self) -> Option<Instant> {
|
pub async fn next(&mut self) -> Option<Instant> {
|
||||||
use async_util::future::poll_fn;
|
|
||||||
|
|
||||||
poll_fn(|cx| self.poll_next(cx)).await
|
poll_fn(|cx| self.poll_next(cx)).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user