Sha256: 4c81607472a85c5d87a5fe8a510a24cf1e8793fedf7f6cd6741ba1efd66615cd

Contents?: true

Size: 1.22 KB

Versions: 27

Compression:

Stored size: 1.22 KB

Contents

use futures::channel::oneshot;
use futures::executor::block_on;
use futures::future::{abortable, Aborted, FutureExt};
use futures::task::{Context, Poll};
use futures_test::task::new_count_waker;

#[test]
fn abortable_works() {
    let (_tx, a_rx) = oneshot::channel::<()>();
    let (abortable_rx, abort_handle) = abortable(a_rx);

    abort_handle.abort();
    assert!(abortable_rx.is_aborted());
    assert_eq!(Err(Aborted), block_on(abortable_rx));
}

#[test]
fn abortable_awakens() {
    let (_tx, a_rx) = oneshot::channel::<()>();
    let (mut abortable_rx, abort_handle) = abortable(a_rx);

    let (waker, counter) = new_count_waker();
    let mut cx = Context::from_waker(&waker);

    assert_eq!(counter, 0);
    assert_eq!(Poll::Pending, abortable_rx.poll_unpin(&mut cx));
    assert_eq!(counter, 0);

    abort_handle.abort();
    assert_eq!(counter, 1);
    assert!(abortable_rx.is_aborted());
    assert_eq!(Poll::Ready(Err(Aborted)), abortable_rx.poll_unpin(&mut cx));
}

#[test]
fn abortable_resolves() {
    let (tx, a_rx) = oneshot::channel::<()>();
    let (abortable_rx, _abort_handle) = abortable(a_rx);

    tx.send(()).unwrap();

    assert!(!abortable_rx.is_aborted());
    assert_eq!(Ok(Ok(())), block_on(abortable_rx));
}

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/futures-0.3.31/tests/future_abortable.rs
wasmtime-29.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_abortable.rs
wasmtime-28.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_abortable.rs
wasmtime-27.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_abortable.rs
wasmtime-26.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_abortable.rs
wasmtime-25.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-25.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-25.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-24.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-23.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-22.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-21.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-20.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-20.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-18.0.3 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-17.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-17.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-16.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-15.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs
wasmtime-15.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_abortable.rs