diff options
-rw-r--r-- | async-await/Cargo.toml | 2 | ||||
-rw-r--r-- | async-await/tests/macros.rs | 22 | ||||
-rw-r--r-- | azure-pipelines.yml | 15 | ||||
-rw-r--r-- | ci/azure-cargo-check.yml | 4 | ||||
-rw-r--r-- | ci/azure-test-nightly.yml | 23 | ||||
-rw-r--r-- | tokio-macros/src/lib.rs | 2 | ||||
-rw-r--r-- | tokio/src/runtime/current_thread/async_await.rs | 17 | ||||
-rw-r--r-- | tokio/src/runtime/current_thread/mod.rs | 3 |
8 files changed, 73 insertions, 15 deletions
diff --git a/async-await/Cargo.toml b/async-await/Cargo.toml index f7833fc2..e605da60 100644 --- a/async-await/Cargo.toml +++ b/async-await/Cargo.toml @@ -37,7 +37,7 @@ tokio-codec = { path = "../tokio-codec" } tokio-current-thread = { path = "../tokio-current-thread" } tokio-executor = { path = "../tokio-executor" } tokio-fs = { path = "../tokio-fs" } -# tokio-futures = { path = "../" } +tokio-futures = { path = "../tokio-futures" } tokio-io = { path = "../tokio-io" } tokio-reactor = { path = "../tokio-reactor" } tokio-signal = { path = "../tokio-signal" } diff --git a/async-await/tests/macros.rs b/async-await/tests/macros.rs new file mode 100644 index 00000000..285e5538 --- /dev/null +++ b/async-await/tests/macros.rs @@ -0,0 +1,22 @@ +#![feature(await_macro, async_await)] + +use tokio::await; +use tokio::timer::Delay; +use std::time::{Duration, Instant}; + +#[tokio::test] +async fn success_no_async() { + assert!(true); +} + +#[tokio::test] +#[should_panic] +async fn fail_no_async() { + assert!(false); +} + +#[tokio::test] +async fn use_timer() { + let when = Instant::now() + Duration::from_millis(10); + await!(Delay::new(when)); +} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 434702f9..3be914e2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -71,17 +71,12 @@ jobs: tokio-buf: - util -# Check async / await -- template: ci/azure-cargo-check.yml +# Run async-await tests +- template: ci/azure-test-nightly.yml parameters: - name: async_await - displayName: Async / Await + name: test_nightly + displayName: Test Async / Await rust: nightly-2019-04-25 - noDefaultFeatures: '' - benches: true - crates: - tokio: - - async-await-preview # Try cross compiling - template: ci/azure-cross-compile.yml @@ -113,7 +108,7 @@ jobs: - test_sub_cross - test_linux - features - - async_await + - test_nightly - cross_32bit_linux - minrust - tsan diff --git a/ci/azure-cargo-check.yml b/ci/azure-cargo-check.yml index b8a3b9e3..5bf7af20 100644 --- a/ci/azure-cargo-check.yml +++ b/ci/azure-cargo-check.yml @@ -27,7 +27,3 @@ jobs: - script: cargo check ${{ parameters.noDefaultFeatures }} --features ${{ feature }} displayName: Check `${{ crate.key }}`, features = ${{ feature }} workingDirectory: $(Build.SourcesDirectory)/${{ crate.key }} - - - ${{ if parameters.benches }}: - - script: cargo check --benches --all - displayName: Check benchmarks diff --git a/ci/azure-test-nightly.yml b/ci/azure-test-nightly.yml new file mode 100644 index 00000000..a845d7c2 --- /dev/null +++ b/ci/azure-test-nightly.yml @@ -0,0 +1,23 @@ +jobs: +- job: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + pool: + vmImage: ubuntu-16.04 + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: ${{ parameters.rust }} + + - template: azure-patch-crates.yml + + - script: cargo test + displayName: cargo +nightly test -p async-await + workingDirectory: $(Build.SourcesDirectory)/async-await + + - script: cargo check --all + displayName: cargo +nightly check --all + + # Check benches + - script: cargo check --benches --all + displayName: Check benchmarks diff --git a/tokio-macros/src/lib.rs b/tokio-macros/src/lib.rs index afe3b1f5..d501f743 100644 --- a/tokio-macros/src/lib.rs +++ b/tokio-macros/src/lib.rs @@ -58,6 +58,7 @@ pub fn test(_attr: TokenStream, item: TokenStream) -> TokenStream { let ret = &input.decl.output; let name = &input.ident; let body = &input.block; + let attrs = &input.attrs; if input.asyncness.is_none() { let tokens = quote_spanned! { input.span() => @@ -69,6 +70,7 @@ pub fn test(_attr: TokenStream, item: TokenStream) -> TokenStream { let result = quote! { #[test] + #(#attrs)* fn #name() #ret { let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap(); rt.block_on_async(async { #body }) diff --git a/tokio/src/runtime/current_thread/async_await.rs b/tokio/src/runtime/current_thread/async_await.rs new file mode 100644 index 00000000..7a259941 --- /dev/null +++ b/tokio/src/runtime/current_thread/async_await.rs @@ -0,0 +1,17 @@ +use super::Runtime; +use std::future::Future; + +impl Runtime { + /// Like `block_on`, but takes an `async` block + pub fn block_on_async<F>(&mut self, future: F) -> F::Output + where + F: Future, + { + use tokio_futures::compat; + + match self.block_on(compat::infallible_into_01(future)) { + Ok(v) => v, + Err(_) => unreachable!(), + } + } +} diff --git a/tokio/src/runtime/current_thread/mod.rs b/tokio/src/runtime/current_thread/mod.rs index 45dc4efe..eb0358df 100644 --- a/tokio/src/runtime/current_thread/mod.rs +++ b/tokio/src/runtime/current_thread/mod.rs @@ -69,6 +69,9 @@ mod builder; mod runtime; +#[cfg(feature = "async-await-preview")] +mod async_await; + pub use self::builder::Builder; pub use self::runtime::{Runtime, Handle}; pub use tokio_current_thread::spawn; |