diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-11-07 20:51:33 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-11-07 20:51:33 -0500 |
commit | 8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633 (patch) | |
tree | 7d02121611582d9beb4e5c6c04edbc5bc581400c | |
parent | 4147a9a39b362468cc6f16c8ce751ee3481321f4 (diff) | |
download | ziglings-8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633.tar.gz ziglings-8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633.tar.bz2 ziglings-8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633.tar.xz ziglings-8ff0cf67e113dd94eaa4f2cb9aa7afdac56e9633.zip |
Added ex91 - closing in on async!
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | exercises/091_async8.zig | 35 | ||||
-rw-r--r-- | patches/patches/091_async8.patch | 16 |
3 files changed, 55 insertions, 0 deletions
@@ -443,6 +443,10 @@ const exercises = [_]Exercise{ .main_file = "090_async7.zig", .output = "beef? BEEF!", }, + .{ + .main_file = "091_async8.zig", + .output = "ABCDEF", + }, }; /// Check the zig version to make sure it can compile the examples properly. 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", .{}); +} diff --git a/patches/patches/091_async8.patch b/patches/patches/091_async8.patch new file mode 100644 index 0000000..8a93b31 --- /dev/null +++ b/patches/patches/091_async8.patch @@ -0,0 +1,16 @@ +20c20 +< print("X", .{}); +--- +> print("D", .{}); +28c28 +< print("X", .{}); +--- +> print("B", .{}); +31c31 +< print("X", .{}); +--- +> print("C", .{}); +34c34 +< print("X", .{}); +--- +> print("E", .{}); |