Skip to content

Commit

Permalink
migrate to tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 25, 2018
1 parent 565bcfb commit 690169d
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 162 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cache:

matrix:
include:
- rust: 1.24.0
- rust: 1.25.0
- rust: stable
- rust: beta
- rust: nightly
Expand All @@ -31,12 +31,12 @@ before_script:

script:
- |
if [[ "$TRAVIS_RUST_VERSION" != "1.24.0" ]]; then
if [[ "$TRAVIS_RUST_VERSION" != "1.25.0" ]]; then
cargo clean
cargo test --features="alpn,tls" -- --nocapture
fi
- |
if [[ "$TRAVIS_RUST_VERSION" == "1.24.0" ]]; then
if [[ "$TRAVIS_RUST_VERSION" == "1.25.0" ]]; then
bash <(curl https://raw.githubusercontent.com/xd009642/tarpaulin/master/travis-install.sh)
USE_SKEPTIC=1 cargo tarpaulin --out Xml --no-count
bash <(curl -s https://codecov.io/bash)
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [0.7.0] - 2018-xx-xx

### Changed

* Migrate to tokio


## [0.6.10] - 2018-05-24

Expand Down
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ flate2-c = ["flate2/miniz-sys"]
flate2-rust = ["flate2/rust_backend"]

[dependencies]
actix = "^0.5.5"
#actix = "^0.6.0"
actix = { git="https://github.com/actix/actix.git" }

base64 = "0.9"
bitflags = "1.0"
Expand All @@ -62,7 +63,7 @@ mime = "0.3"
mime_guess = "2.0.0-alpha"
num_cpus = "1.0"
percent-encoding = "1.0"
rand = "0.4"
rand = "0.5"
regex = "1.0"
serde = "1.0"
serde_json = "1.0"
Expand All @@ -86,8 +87,11 @@ byteorder = "1"
futures = "0.1"
futures-cpupool = "0.1"
slab = "0.4"
tokio = "0.1"
tokio-io = "0.1"
tokio-core = "0.1"
tokio-tcp = "0.1"
tokio-timer = "0.2"
tokio-reactor = "0.1"

# native-tls
native-tls = { version="0.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Actix web is a simple, pragmatic and extremely fast web framework for Rust.
* [API Documentation (Releases)](https://docs.rs/actix-web/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-web](https://crates.io/crates/actix-web)
* Minimum supported Rust version: 1.24 or later
* Minimum supported Rust version: 1.25 or later

## Example

Expand Down
15 changes: 7 additions & 8 deletions src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/client/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use http_range::HttpRangeParseError;
use httparse;
use serde::de::value::Error as DeError;
use serde_json::error::Error as JsonError;
use tokio_timer::Error as TimerError;
pub use url::ParseError as UrlParseError;

// re-exports
Expand Down Expand Up @@ -126,6 +127,9 @@ impl From<failure::Error> for Error {
/// `InternalServerError` for `JsonError`
impl ResponseError for JsonError {}

/// `InternalServerError` for `TimerError`
impl ResponseError for TimerError {}

/// `InternalServerError` for `UrlParseError`
impl ResponseError for UrlParseError {}

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ extern crate mio;
extern crate net2;
extern crate rand;
extern crate slab;
extern crate tokio_core;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_reactor;
extern crate tokio_tcp;
extern crate tokio_timer;
extern crate url;
#[macro_use]
extern crate serde;
Expand Down
6 changes: 3 additions & 3 deletions src/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ mod tests {
use bytes::Bytes;
use futures::future::{lazy, result};
use payload::{Payload, PayloadWriter};
use tokio_core::reactor::Core;
use tokio::runtime::current_thread::Runtime;

#[test]
fn test_boundary() {
Expand Down Expand Up @@ -710,9 +710,9 @@ mod tests {

#[test]
fn test_multipart() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);

let bytes = Bytes::from(
Expand Down
30 changes: 15 additions & 15 deletions src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ mod tests {
use failure::Fail;
use futures::future::{lazy, result};
use std::io;
use tokio_core::reactor::Core;
use tokio::runtime::current_thread::Runtime;

#[test]
fn test_error() {
Expand All @@ -542,9 +542,9 @@ mod tests {

#[test]
fn test_basic() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (_, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand All @@ -559,9 +559,9 @@ mod tests {

#[test]
fn test_eof() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand All @@ -584,9 +584,9 @@ mod tests {

#[test]
fn test_err() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand All @@ -602,9 +602,9 @@ mod tests {

#[test]
fn test_readany() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand All @@ -631,9 +631,9 @@ mod tests {

#[test]
fn test_readexactly() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand Down Expand Up @@ -665,9 +665,9 @@ mod tests {

#[test]
fn test_readuntil() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (mut sender, payload) = Payload::new(false);
let mut payload = PayloadHelper::new(payload);

Expand Down Expand Up @@ -699,9 +699,9 @@ mod tests {

#[test]
fn test_unread_data() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let (_, mut payload) = Payload::new(false);

payload.unread_data(Bytes::from("data"));
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ mod tests {
use actix::*;
use context::HttpContext;
use futures::future::{lazy, result};
use tokio_core::reactor::Core;
use tokio::runtime::current_thread::Runtime;

impl<S, H> PipelineState<S, H> {
fn is_none(&self) -> Option<bool> {
Expand All @@ -796,9 +796,9 @@ mod tests {

#[test]
fn test_completed() {
Core::new()
Runtime::new()
.unwrap()
.run(lazy(|| {
.block_on(lazy(|| {
let mut info = PipelineInfo::new(HttpRequest::default());
Completed::<(), Inner<()>>::init(&mut info)
.is_none()
Expand Down
Loading

0 comments on commit 690169d

Please sign in to comment.