Module tokio_test::task

source ·
Expand description

Futures task based helpers to easily test futures and manually written futures.

The Spawn type is used as a mock task harness that allows you to poll futures without needing to setup pinning or context. Any future can be polled but if the future requires the tokio async context you will need to ensure that you poll the Spawn within a tokio context, this means that as long as you are inside the runtime it will work and you can poll it via Spawn.

Spawn also supports Stream to call poll_next without pinning or context.

In addition to circumventing the need for pinning and context, Spawn also tracks the amount of times the future/task was woken. This can be useful to track if some leaf future notified the root task correctly.

§Example

use tokio_test::task;

let fut = async {};

let mut task = task::spawn(fut);

assert!(task.poll().is_ready(), "Task was not ready!");

Structs§

  • Future spawned on a mock task that can be used to poll the future or stream without needing pinning or context types.

Functions§

  • Spawn a future into a Spawn which wraps the future in a mocked executor.