pub struct QueuedRuntime { /* private fields */ }
Expand description

A very small async runtime, with support for adding more tasks as it runs. This uses a VecDeque internally.

Implementations§

Creates a new, empty QueuedRuntime. Awaiting this does nothing until futures are pushed to it.

Examples found in repository?
examples/tcp.rs (line 14)
13
14
15
16
17
fn main() {
    let mut runtime = QueuedRuntime::new();
    runtime.push(go(("0.0.0.0", 5000)));
    sync(runtime);
}
More examples
Hide additional examples
examples/recursion.rs (line 5)
4
5
6
7
8
fn main() {
    let mut runtime = QueuedRuntime::new();
    runtime.push(print_something_after_ms(0));
    sync(runtime);
}
examples/runtime.rs (line 5)
4
5
6
7
8
9
10
fn main() {
    let mut runtime = QueuedRuntime::new();
    for _ in 0..50 {
        runtime.push(print_something_after_ms(2000));
    }
    sync(runtime);
}
src/queued_runtime.rs (line 65)
64
65
66
    fn default() -> Self {
        Self::new()
    }

Adds a new future to the queue to be completed.

Adds a new future to the queue to be completed.

Examples found in repository?
examples/tcp.rs (line 15)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() {
    let mut runtime = QueuedRuntime::new();
    runtime.push(go(("0.0.0.0", 5000)));
    sync(runtime);
}

async fn go(addr: (&str, u16)) {
    let mut listener = TcpListener::bind(addr).unwrap();
    loop {
        get_current_runtime()
            .await
            .push(handle(accept(&mut listener).await.unwrap()));
    }
}
More examples
Hide additional examples
examples/recursion.rs (line 6)
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut runtime = QueuedRuntime::new();
    runtime.push(print_something_after_ms(0));
    sync(runtime);
}

async fn print_something_after_ms(ms: u64) {
    wait_ms(ms).await;
    println!("something after {ms}ms! :D");
    get_current_runtime().await.push(print_something_after_ms(ms + 1));
}
examples/runtime.rs (line 7)
4
5
6
7
8
9
10
fn main() {
    let mut runtime = QueuedRuntime::new();
    for _ in 0..50 {
        runtime.push(print_something_after_ms(2000));
    }
    sync(runtime);
}

Trait Implementations§

Returns the “default value” for a type. Read more
The type of value produced on completion.
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. 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 output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
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.