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§
- Future
Handle - A handle to the future task
- Future
Queue - A queue for polling futures. It is stored in here until
FutureQueue::pollis run.
Enums§
- Future
Status - 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.
- Future
Storage - A type for storing the queue. It uses a
VecDequeto storeFutureHandle’s andBoxFuture - Throwable
- A type recommended to be used by
FutureQueueto allow being thrown around in your app