aboutsummaryrefslogtreecommitdiff
path: root/exercises/085_async2.zig
blob: cec5c2b42180ff9bb12cb7d7a2915faf2520c09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// So, 'suspend' returns control to the place from which it was
// called (the "call site"). How do we control back to the
// suspended function?
//
// For that, we have a new keyword called 'resume' which takes an
// async function invocation's frame and returns control to it.
//
//     fn fooThatSuspends() void {
//         suspend {}
//     }
//
//     var foo_frame = async fooThatSuspends();
//     resume foo_frame;
//
// See if you can make this program print "Hello async!".
//
const print = @import("std").debug.print;

pub fn main() void {
    var foo_frame = async foo();
}

fn foo() void {
    print("Hello ", .{});
    suspend {}
    print("async!\n", .{});
}