Crate dropbear_future_queue

Crate dropbear_future_queue 

Source
Expand description

Enabling multithreading for functions and apps that are purely single threaded.

This was originally a module in my dropbear game engine, however I thought there were barely any libraries that had future queuing. It takes inspiration from Unity and how they handle their events.

§Example

use dropbear_future_queue::{FutureQueue, FutureStatus};

// create new queue
let queue = FutureQueue::new();

// create a new handle to keep for reference
let handle = queue.push(async move {
    tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
    67 + 41
});

// Check initial status
assert!(matches!(queue.get_status(&handle), Some(FutureStatus::NotPolled)));

// execute the futures
queue.poll();

// Wait a bit for completion and check result
tokio::time::sleep(tokio::time::Duration::from_millis(20)).await;

if let Some(result) = queue.exchange_as::<i32>(&handle) {
    println!("67 + 41 = {}", result);
    assert_eq!(result, 108);
}

Structs§

FutureHandle
A handle to the future task
FutureQueue
A queue for polling futures. It is stored in here until FutureQueue::poll is run.

Enums§

FutureStatus
A status showing the future, used by the [ResultReceiver] and [ResultSender]

Type Aliases§

AnyResult
A clonable generic result. It can/preferred to be downcasted to your specific type.
BoxFuture
A type used for a future.
FutureStorage
A type for storing the queue. It uses a VecDeque to store FutureHandle’s and BoxFuture
Throwable
A type recommended to be used by FutureQueue to allow being thrown around in your app