switch-resume 0.1.3

Delimited async continuations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    futures::executor::block_on(async {
        async fn bar(resume: switch_resume::Resume<'_, i32, i32>) -> i32 {
            println!("foo has been paused, started bar");
            let resume_result = resume(69).await;
            assert_eq!(resume_result, -1); // This is the result of foo
            420 // This is the final result of task
        }
        async fn foo(task: switch_resume::Task<'_, i32>) -> i32 {
            println!("foo started");
            let value = task.switch(bar).await;
            println!("foo was resumed with {value}. Nice!");
            -1 // This is not the final task result since we switched to bar
        }
        let task_result = switch_resume::run(foo).await;
        assert_eq!(task_result, 420);
    });
}