tokio-interruptible-future
Easily interrupt async code in given check points. It's useful to interrupt threads/fibers.
DISCLAIMER: Not enough tested.
TODO: Add documentation.
Recommended to use together with tokio-interruptible-future.
```rust
[derive(Debug, PartialEq, Eq)]
enum MyError {
Interrupted(InterruptError),
}
impl From for MyError {
fn from(value: InterruptError) -> Self {
Self::Interrupted(value)
}
}
struct Test {
interruptnotifier: Notify,
}
impl Interruptible for Test {
fn interruptnotifier(&self) -> &Notify {
&self.interruptnotifier
}
}
impl Test {
pub fn new() -> Self {
Self {
interruptnotifier: Notify::new()
}
}
pub async fn f(&self) -> Result<(), MyError> {
self.interruptible/::<(), MyError>/(async {
loop {
self.interrupt(); // In real code called from another fiber or another thread.
self.checkforinterrupt::().await?;
}
}).await
}
pub async fn g(&self) -> Result {
self.interruptible::(async {
Ok(123)
}).await
}
}
```