Skip to content
Streamline updating a Tokio 0.1 application to Tokio 0.2.
Rust
Branch: master
Clone or download
hawkw update to tokio 0.2 release version (#6)
## Motivation

Currently, `tokio-compat` depends on `tokio` 0.2.0-alpha.6, rather than
the release version of 0.2. Several APIs have changed significantly
between alpha.6 and release.

## Solution

This branch updates `tokio-compat` to depend on the release 0.2.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Latest commit 1f64002 Dec 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows add a quick CI config (#7) Dec 6, 2019
src update to tokio 0.2 release version (#6) Dec 10, 2019
tests update to tokio 0.2 release version (#6) Dec 10, 2019
.gitignore Initial import Nov 1, 2019
Cargo.toml update to tokio 0.2 release version (#6) Dec 10, 2019
README.md Initial import Nov 1, 2019

README.md

Tokio Compat

Compatibility layers between tokio 0.2 and legacy versions.

Crates.io MIT licensed Build Status Gitter chat

Website | Guides | API Docs | Chat

Overview

This crate provides compatibility runtimes that allow running both futures 0.1 futures that use tokio 0.1 runtime services and std::future futures that use tokio 0.2 runtime services.

Examples

Spawning both tokio 0.1 and tokio 0.2 futures:

use futures_01::future::lazy;

tokio_compat::run(lazy(|| {
    // spawn a `futures` 0.1 future using the `spawn` function from the
    // `tokio` 0.1 crate:
    tokio_01::spawn(lazy(|| {
        println!("hello from tokio 0.1!");
        Ok(())
    }));

    // spawn an `async` block future on the same runtime using `tokio`
    // 0.2's `spawn`:
    tokio_02::spawn(async {
        println!("hello from tokio 0.2!");
    });

    Ok(())
}))

Futures on the compat runtime can use timer APIs from both 0.1 and 0.2 versions of tokio:

use std::time::{Duration, Instant};
use futures_01::future::lazy;
use tokio_compat::prelude::*;

tokio_compat::run_std(async {
    // Wait for a `tokio` 0.1 `Delay`...
    let when = Instant::now() + Duration::from_millis(10);
    tokio_01::timer::Delay::new(when)
        // convert the delay future into a `std::future` that we can `await`.
        .compat()
        .await
        .expect("tokio 0.1 timer should work!");
    println!("10 ms have elapsed");

    // Wait for a `tokio` 0.2 `Delay`...
    let when = Instant::now() + Duration::from_millis(20);
    tokio_02::timer::delay(when).await;
    println!("20 ms have elapsed");
});

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.

You can’t perform that action at this time.