Added ex91 - closing in on async!
This commit is contained in:
parent
4147a9a39b
commit
8ff0cf67e1
3 changed files with 55 additions and 0 deletions
35
exercises/091_async8.zig
Normal file
35
exercises/091_async8.zig
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// 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();
|
||||
|
||||
print("X", .{});
|
||||
|
||||
resume frame;
|
||||
|
||||
print("F", .{});
|
||||
}
|
||||
|
||||
fn suspendable() void {
|
||||
print("X", .{});
|
||||
|
||||
suspend {
|
||||
print("X", .{});
|
||||
}
|
||||
|
||||
print("X", .{});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue