Skip to content

Commit

Permalink
Upgrade to Tokio 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Diggsey committed Jan 13, 2021
1 parent f2e4ac6 commit fbd68f0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "act-zero"
version = "0.3.0"
version = "0.4.0"
authors = ["Diggory Blake <[email protected]>"]
edition = "2018"
description = "Ergonomic actor system"
Expand All @@ -21,13 +21,13 @@ tracing = ["tynm"]
futures = "0.3.6"
async-trait = "0.1.41"
log = "0.4.11"
tokio = { version = "0.2.22", features = ["rt-core", "time"], optional = true }
async-std = { version = "1.6.5", optional = true }
tokio = { version = "1.0.1", features = ["time", "net"], optional = true }
async-std = { version = "1.8.0", optional = true }
tynm = { version = "0.1.4", optional = true }

[dev-dependencies]
tokio = { version = "0.2.22", features = ["macros", "blocking"] }
async-std = { version = "1.6.5", features = ["attributes"] }
tokio = { version = "1.0.1", features = ["rt", "macros", "time"] }
async-std = { version = "1.8.0", features = ["attributes"] }

[[example]]
name = "using_tokio"
Expand Down
2 changes: 1 addition & 1 deletion src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::Addr;

/// The type of error returned by an actor method.
pub type ActorError = Box<dyn Error + Send + Sync>;
/// Short alias for a `Result<T, ActorError>`.
/// Short alias for a `Result<Produces<T>, ActorError>`.
pub type ActorResult<T> = Result<Produces<T>, ActorError>;

/// A concrete type similar to a `BoxFuture<'static, Result<T, oneshot::Canceled>>`, but
Expand Down
4 changes: 2 additions & 2 deletions src/runtimes/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl Spawn for Runtime {
}

impl timer::SupportsTimers for Runtime {
type Delay = tokio::time::Delay;
type Delay = tokio::time::Sleep;
fn delay(&self, deadline: Instant) -> Self::Delay {
tokio::time::delay_until(deadline.into())
tokio::time::sleep_until(deadline.into())
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::time::{Duration, Instant};

use async_trait::async_trait;
use futures::future::FutureExt;
use futures::select_biased;
use futures::{pin_mut, select_biased};

use crate::{send, upcast, Actor, ActorResult, Addr, AddrLike, WeakAddr};

/// Timers can be used on runtimes implementing this trait.
pub trait SupportsTimers {
/// The type of future returned by `delay`.
type Delay: Future<Output = ()> + Send + Unpin + 'static;
type Delay: Future<Output = ()> + Send + 'static;

/// Create a future which will complete when the deadline
/// is passed.
Expand Down Expand Up @@ -268,8 +268,10 @@ impl<R: SupportsTimers> Timer<R> {
f: impl FnOnce(A) -> F + Send + 'static,
) {
let addr2 = addr.clone();
let mut delay = self.runtime.delay(deadline).fuse();
let delay = self.runtime.delay(deadline).fuse();

addr.send_fut(async move {
pin_mut!(delay);
if select_biased! {
_ = f(addr2.clone()).fuse() => true,
_ = delay => false,
Expand Down

0 comments on commit fbd68f0

Please sign in to comment.