Expand description
§Async Coroutine
This crate provides a coroutine implementation based on Rust’s async/await syntax.
§Usage
use async_coroutine::{Coroutine, State};
let mut co = Coroutine::new(|handle, value| async move {
assert_eq!(value, 1);
assert_eq!(handle.yield_(true).await, 2);
assert_eq!(handle.yield_(false).await, 3);
"Bye"
});
assert_eq!(co.resume_with(1), State::Yield(true));
assert_eq!(co.resume_with(2), State::Yield(false));
assert_eq!(co.resume_with(3), State::Complete("Bye"));Structs§
- Coroutine
- A coroutine that can yield values of type
Y, can be resumed with a value of typeRand completes with a value of typeT. - Yield
Handle - The yield handle can be used from within the coroutine to yield values and receive a resume value when the coroutine is resumed.
Enums§
- State
- Represents the state of a coroutine, which can either yield a value of type
Yor complete with a value of typeT.
Type Aliases§
- Generator
- A generator is a coroutine that does not have a resume value.