Skip to content
CryoCryo home
Stdlibtest

pending

import std::test::pending; · source

A test's future that is pending a set number of times and then ready, to drive the suspend and resume paths of async code without any I/O or threads.

Types

PendingThenReady<T>

type struct PendingThenReady<T> {
    private remaining: u32;
    private value:     Option<T>;
}

PendingThenReady::new(n, value) answers Poll::Pending to its first n polls and then Poll::Ready(value); a count of 0 makes it ready at once. Its Pending polls do not wake the context's waker, so it completes only under a driver that polls again unprompted, as future::block_on does. Awaiting one is a suspension point like any real I/O, so a test can check what an async function does across a suspend. Polling it after it completed panics.

import std::future::{ block_on };
import std::test::pending::{ PendingThenReady };

async function add_later(a: i64) -> i64 {
    const b: i64 = await PendingThenReady::<i64>::new(2, 10);
    return a + b;
}

function main() -> int {
    return if (block_on(add_later(5)) == 15) { 0 } else { 1 };
}

Constructors

static new(pending_count: u32, value: T) -> PendingThenReady<T>;

A future that returns Pending from its first pending_count polls and completes with value on the next; a pending_count of 0 makes it ready at once. Its Pending polls do not wake the context's waker, so it completes only under a driver that polls again unprompted.

Trait implementations

implement<T> trait Future<T> for struct PendingThenReady<T>