[][src]Crate ndless_async

Ndless-specific integration with async/await

This crate provides an executor, reactor, and utilities to use Rust's async capabilities with the TI Nspire's timer and keypad. Note that normally async functions are used for I/O. However, as far as I'm aware, the TI-Nspire's OS has no support for asynchronous I/O of any sort. However, this still provides helpful utilities for doing multiple things at once, such as waiting for a key with a timeout.

You'll first need to create an instance of AsyncListeners with AsyncListeners::default(). This allows you to receive events from the Nspire's timer. From there, you can pass it into task::block_on, along with a Future of your choice.

Helpful resources

Check out the Rust Async Book. This has useful instructions about asynchronous programming. Although it is mostly written for usage with a full operating system, everything applies here except chapters 1.4, 6.3, 8, and 10.

futures_util has many useful utility functions. Add it to your project by adding the following to your Cargo.toml:

futures-util = { version = "0.3.5", default-features = false, features = ["alloc", "async-await-macro"] }

You may find its FuturesUnordered to be of help for scheduling multiple tasks. Although macros like join and first can be helpful, they aren't as efficient and flexible as it.

The macros join, select, try_join, and traits FutureExt & StreamExt are re-exported from it, so if that's all you need, you don't need to depend on it directly.


use futures_util::future;
use ndless_async::task::{block_on, AsyncListeners};
use ndless_async::{first, StreamExt};
use ndless_async::keypad::KeypadListener;
use ndless::input::Key;

let listeners = AsyncListeners::new();
let keypad = KeypadListener::new(&listeners.timer());
block_on(&listeners, async {
    let _ = listeners.timer().timeout_ms(5000, do_stuff(&keypad)).await;
    first!(do_other_stuff(&listeners), wait_for_esc(&keypad));

async fn wait_for_esc(keypad: &KeypadListener<'_>) {
        .filter(|key| future::ready(key.key == Key::Esc))

async fn do_other_stuff(listeners: &AsyncListeners) {
    loop {

async fn do_stuff(keypad: &KeypadListener<'_>) {
    use ndless_async::keypad::KeyState::*;
    let mut keypad = keypad.stream();
    while let Some(event) = keypad.next().await {
            "Key {:?} was {}",
            if event.state == Released {
            } else {
        print!("Keys currently pressed: ");
            .for_each(|key| print!("{:?} ", key));
        if event.key == Key::Esc { break; }



Listens for button presses and releases from the keypad.


A multi-producer, single-consumer queue for sending values across asynchronous tasks.


Main task executing functionality


Timers, Timeouts, and Intervals



Polls for the first future to complete, and then cancels the remaining ones. If you care about the return value, use select. This macro must be used in an async context, such as an async fn or async { } block.


Polls multiple futures simultaneously, returning a tuple of all results once complete.


Polls multiple futures and streams simultaneously, executing the branch for the future that finishes first. Unlike select!, if multiple futures are ready, one will be selected in order of declaration. Futures directly passed to select_biased! must be Unpin and implement FusedFuture.


Polls multiple futures simultaneously, resolving to a Result containing either a tuple of the successful outputs or an error.



Allows other tasks to run. See AsyncListeners::yield_now for more details.



An extension trait for Futures that provides a variety of convenient adapters.


An extension trait for Streams that provides a variety of convenient combinator functions.