From 8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633 Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sun, 7 Nov 2021 20:51:33 -0500 Subject: Added ex91 - closing in on async! --- exercises/091_async8.zig | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 exercises/091_async8.zig (limited to 'exercises/091_async8.zig') diff --git a/exercises/091_async8.zig b/exercises/091_async8.zig new file mode 100644 index 0000000..cd9c975 --- /dev/null +++ b/exercises/091_async8.zig @@ -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", .{}); +} -- cgit v1.2.3-ZIG