mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 02:19:22 +02:00
migrate to tokio
This commit is contained in:
@ -9,16 +9,16 @@ use actix::actors::{Connect as ResolveConnect, Connector, ConnectorError};
|
||||
use actix::fut::WrapFuture;
|
||||
use actix::registry::ArbiterService;
|
||||
use actix::{
|
||||
fut, Actor, ActorFuture, ActorResponse, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, Supervised, Syn,
|
||||
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
|
||||
Handler, Message, Recipient, Supervised, Syn,
|
||||
};
|
||||
|
||||
use futures::task::{current as current_task, Task};
|
||||
use futures::unsync::oneshot;
|
||||
use futures::{Async, Future, Poll};
|
||||
use http::{Error as HttpError, HttpTryFrom, Uri};
|
||||
use tokio_core::reactor::Timeout;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::Delay;
|
||||
|
||||
#[cfg(feature = "alpn")]
|
||||
use openssl::ssl::{Error as OpensslError, SslConnector, SslMethod};
|
||||
@ -190,8 +190,8 @@ pub struct ClientConnector {
|
||||
available: HashMap<Key, VecDeque<Conn>>,
|
||||
to_close: Vec<Connection>,
|
||||
waiters: HashMap<Key, VecDeque<Waiter>>,
|
||||
wait_timeout: Option<(Instant, Timeout)>,
|
||||
paused: Option<Option<(Instant, Timeout)>>,
|
||||
wait_timeout: Option<(Instant, Delay)>,
|
||||
paused: Option<Option<(Instant, Delay)>>,
|
||||
}
|
||||
|
||||
impl Actor for ClientConnector {
|
||||
@ -563,8 +563,7 @@ impl ClientConnector {
|
||||
}
|
||||
}
|
||||
|
||||
let mut timeout =
|
||||
Timeout::new(time - Instant::now(), Arbiter::handle()).unwrap();
|
||||
let mut timeout = Delay::new(time);
|
||||
let _ = timeout.poll();
|
||||
self.wait_timeout = Some((time, timeout));
|
||||
}
|
||||
@ -597,7 +596,7 @@ impl Handler<Pause> for ClientConnector {
|
||||
fn handle(&mut self, msg: Pause, _: &mut Self::Context) {
|
||||
if let Some(time) = msg.time {
|
||||
let when = Instant::now() + time;
|
||||
let mut timeout = Timeout::new(time, Arbiter::handle()).unwrap();
|
||||
let mut timeout = Delay::new(when);
|
||||
let _ = timeout.poll();
|
||||
self.paused = Some(Some((when, timeout)));
|
||||
} else if self.paused.is_none() {
|
||||
|
@ -10,7 +10,7 @@
|
||||
//! fn main() {
|
||||
//! let sys = actix::System::new("test");
|
||||
//!
|
||||
//! actix::Arbiter::handle().spawn({
|
||||
//! actix::Arbiter::spawn({
|
||||
//! client::get("http://www.rust-lang.org") // <- Create request builder
|
||||
//! .header("User-Agent", "Actix-web")
|
||||
//! .finish().unwrap()
|
||||
@ -70,7 +70,7 @@ impl ResponseError for SendRequestError {
|
||||
/// fn main() {
|
||||
/// let sys = actix::System::new("test");
|
||||
///
|
||||
/// actix::Arbiter::handle().spawn({
|
||||
/// actix::Arbiter::spawn({
|
||||
/// client::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// .header("User-Agent", "Actix-web")
|
||||
/// .finish().unwrap()
|
||||
|
@ -2,9 +2,9 @@ use bytes::{Bytes, BytesMut};
|
||||
use futures::unsync::oneshot;
|
||||
use futures::{Async, Future, Poll};
|
||||
use http::header::CONTENT_ENCODING;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{io, mem};
|
||||
use tokio_core::reactor::Timeout;
|
||||
use tokio_timer::Delay;
|
||||
|
||||
use actix::prelude::*;
|
||||
|
||||
@ -71,7 +71,7 @@ pub struct SendRequest {
|
||||
conn: Addr<Unsync, ClientConnector>,
|
||||
conn_timeout: Duration,
|
||||
wait_timeout: Duration,
|
||||
timeout: Option<Timeout>,
|
||||
timeout: Option<Delay>,
|
||||
}
|
||||
|
||||
impl SendRequest {
|
||||
@ -108,7 +108,7 @@ impl SendRequest {
|
||||
/// Request timeout is the total time before a response must be received.
|
||||
/// Default value is 5 seconds.
|
||||
pub fn timeout(mut self, timeout: Duration) -> Self {
|
||||
self.timeout = Some(Timeout::new(timeout, Arbiter::handle()).unwrap());
|
||||
self.timeout = Some(Delay::new(Instant::now() + timeout));
|
||||
self
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ impl Future for SendRequest {
|
||||
};
|
||||
|
||||
let timeout = self.timeout.take().unwrap_or_else(|| {
|
||||
Timeout::new(Duration::from_secs(5), Arbiter::handle()).unwrap()
|
||||
Delay::new(Instant::now() + Duration::from_secs(5))
|
||||
});
|
||||
|
||||
let pl = Box::new(Pipeline {
|
||||
@ -229,7 +229,7 @@ pub(crate) struct Pipeline {
|
||||
decompress: Option<PayloadStream>,
|
||||
should_decompress: bool,
|
||||
write_state: RunningState,
|
||||
timeout: Option<Timeout>,
|
||||
timeout: Option<Delay>,
|
||||
}
|
||||
|
||||
enum IoBody {
|
||||
|
@ -34,7 +34,7 @@ use httprequest::HttpRequest;
|
||||
/// fn main() {
|
||||
/// let sys = actix::System::new("test");
|
||||
///
|
||||
/// actix::Arbiter::handle().spawn({
|
||||
/// actix::Arbiter::spawn({
|
||||
/// ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// .header("User-Agent", "Actix-web")
|
||||
/// .finish().unwrap()
|
||||
|
Reference in New Issue
Block a user