Module task

Source
Expand description

Main task executing functionality

The main ndless executor and reactor. Calling block_on will wait for the future to complete, then return its result. You’ll often want to combine this with [join] or [first] to run multiple things at once.

§Example

use ndless_async::task::{AsyncListeners, block_on};
use ndless_async::StreamExt;
use ndless::input::Key;
use ndless::prelude::*;

let listeners = AsyncListeners::new();
block_on(&listeners, listen(&listeners));

async fn listen(listeners: &AsyncListeners) {
    let mut keypad = listeners.keypad();
    while let Some(event) = keypad.next().await {
        println!("{:?}", key);
        if event.key == Key::Esc {
            break;
        }
    }
}

Structs§

AsyncListeners
Handler for listening to system events.

Functions§

block_on
Spawns a task and blocks until the future resolves, returning its result.