tomt_async

Crates.iotomt_async
lib.rstomt_async
version0.1.3
sourcesrc
created_at2024-01-23 03:08:13.724431
updated_at2024-01-31 23:27:03.515586
descriptionPrimarily a dumping ground for personal async snippets that may be used in other ToMT projects. If this crate is useful to others please let us know.
homepage
repository
max_upload_size
id1110063
size18,069
TheBeardedQuack (TheBeardedQuack)

documentation

README

Brief

This crate is primarily a dumping ground for personal async snippets that may be used in other ToMT projects.

However should this crate prove useful to others please let us know.

Usage

tomt_async::sync::Mutex

use std::sync::Arc;
use tomt_async::sync::Mutex;

async fn main()
{
    let shared_mutex = Arc::new(Mutex::new(0));

    do_something(shared_mutex.clone()).await;
}

async do_something(
    shared_mutex: Arc<Mutex<i32>>
) {
    let mut lock = shared_mutex.lock().await;
    *lock = *lock + 1;

    // lock is released on drop, though it's highly recommended to avoid
    // calling any async funcs while the lock is held
}

tomt_async::collections::stack

use tomt_async::collections::Stack;

async fn main()
{
    let stack = Stack::<i32>::new();

    stack.push(5).await;
    stack.push(8).await;

    do_something(stack).await;
}

async fn do_something<T: std::fmt::Debug>(
    stack: Stack<T>
) {
    while let Some(item) = stack.pop().await {
        println!("Item = {item:?}");
    }
}
Commit count: 0

cargo fmt