| Crates.io | tomt_async |
| lib.rs | tomt_async |
| version | 0.1.3 |
| created_at | 2024-01-23 03:08:13.724431+00 |
| updated_at | 2024-01-31 23:27:03.515586+00 |
| description | Primarily 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 | |
| id | 1110063 |
| size | 18,069 |
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.
tomt_async::sync::Mutexuse 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::stackuse 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:?}");
}
}