pub struct Cosync<T: ?Sized> { /* private fields */ }
Expand description

A single-threaded, sequential, parameterized async task queue.

This executor allows you to queue multiple tasks in sequence, and to queue tasks within other tasks. Tasks are done in the order they are queued.

You can queue a task by using queue, by spawning a CosyncQueueHandle and calling queue, or, within a task, calling queue_task on CosyncInput.

Implementations

Create a new, empty queue of tasks.

Returns the number of tasks queued. This includes the task currently being executed. Use is_executing to see if there is a task currently being executed (ie, it returned Pending at some point in its execution).

Returns true if no futures are being executed and there are no futures in the queue.

Returns true if cosync has a Pending future. It is possible for the cosync to have no Pending future, but to have tasks queued still.

Creates a queue handle which can be used to spawn tasks.

Adds a new Task to the TaskQueue.

Run all tasks in the queue to completion. You probably want run_until_stall.


let mut cosync: Cosync<i32> = Cosync::new();
cosync.queue(move |mut input| async move {
    let mut input = input.get();
    *input = 10;
});

let mut value = 0;
cosync.run_blocking(&mut value);
assert_eq!(value, 10);

The function will block the calling thread until all tasks in the pool are complete, including any spawned while running existing tasks.

Runs all tasks in the queue and returns if no more progress can be made on any task.

use cosync::{sleep_ticks, Cosync};

let mut cosync = Cosync::new();
cosync.queue(move |mut input| async move {
    *input.get() = 10;
    // this will make the executor stall for a call
    // we call `run_until_stall` an additional time,
    // so we'll complete this 1 tick sleep.
    sleep_ticks(1).await;

    *input.get() = 20;
});

let mut value = 0;
cosync.run_until_stall(&mut value);
assert_eq!(value, 10);
cosync.run_until_stall(&mut value);
assert_eq!(value, 20);

This function will not block the calling thread and will return the moment that there are no tasks left for which progress can be made; remaining incomplete tasks in the pool can continue with further use of one of the pool’s run or poll methods. While the function is running, all tasks in the pool will try to make progress.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.