https://github.com/rogercoll/lullable
Futures wrapper that allows to abort or pause them
https://github.com/rogercoll/lullable
Last synced: about 1 month ago
JSON representation
Futures wrapper that allows to abort or pause them
- Host: GitHub
- URL: https://github.com/rogercoll/lullable
- Owner: rogercoll
- License: mit
- Created: 2023-12-25T10:50:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-25T11:01:04.000Z (over 1 year ago)
- Last Synced: 2025-03-20T14:52:49.431Z (about 1 month ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Lullable (Experimental)
**Lull that task!**
```rust
use std::{
thread::{sleep, spawn},
time::Duration,
};use futures::executor::block_on;
use tokio::task::yield_now;fn main() {
let (cancel, handle) = lullable::lullable(async {
let mut i = 0;
loop {
eprintln!("Iteration number: {}", i);
i += 1;
yield_now().await;
sleep(Duration::from_secs(1))
}
});spawn(move || block_on(cancel));
std::thread::sleep(Duration::from_secs(3));
let pause = handle.pause();
eprintln!("Task paused");std::thread::sleep(Duration::from_secs(3));
drop(pause);eprintln!("Task unpaused");
std::thread::sleep(Duration::from_secs(3));
handle.abort();
eprintln!("Task cancelled")
}
```