ziglings/exercises/091_async8.zig

36 lines
587 B
Zig
Raw Normal View History

2021-11-08 01:51:33 +00:00
//
// You have doubtless noticed that 'suspend' requires a block
// expression like so:
//
// suspend {}
//
// The suspend block executes when a function suspends. To get
// sense for when this happens, please make the following
// program print the string
//
// "ABCDEF"
//
const print = @import("std").debug.print;
pub fn main() void {
print("A", .{});
var frame = async suspendable();
2022-01-02 15:34:05 +00:00
print("D", .{});
2021-11-08 01:51:33 +00:00
resume frame;
print("F", .{});
}
fn suspendable() void {
2022-01-02 15:34:05 +00:00
print("B", .{});
2021-11-08 01:51:33 +00:00
suspend {
2022-01-02 15:34:05 +00:00
print("C", .{});
2021-11-08 01:51:33 +00:00
}
2022-01-02 15:34:05 +00:00
print("E", .{});
2021-11-08 01:51:33 +00:00
}