diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-05-12 21:36:57 -0400 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-05-12 21:36:57 -0400 |
commit | 469d4dfbf40dd5512f53ce1cb022e1aa4639443b (patch) | |
tree | b4a2bc00bed7ea92c6f248eded363ce6b9479687 | |
parent | 5fec2602cff707f5732ac5d821e8bb18ff69ed79 (diff) | |
download | ziglings-469d4dfbf40dd5512f53ce1cb022e1aa4639443b.tar.gz ziglings-469d4dfbf40dd5512f53ce1cb022e1aa4639443b.tar.bz2 ziglings-469d4dfbf40dd5512f53ce1cb022e1aa4639443b.tar.xz ziglings-469d4dfbf40dd5512f53ce1cb022e1aa4639443b.zip |
add ex087 async 4
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | exercises/087_async4.zig | 30 | ||||
-rw-r--r-- | patches/patches/087_async4.patch | 10 |
3 files changed, 44 insertions, 0 deletions
@@ -426,6 +426,10 @@ const exercises = [_]Exercise{ .main_file = "086_async3.zig", .output = "5 4 3 2 1", }, + .{ + .main_file = "087_async4.zig", + .output = "1 2 3 4 5", + }, }; /// Check the zig version to make sure it can compile the examples properly. diff --git a/exercises/087_async4.zig b/exercises/087_async4.zig new file mode 100644 index 0000000..bb9c9ec --- /dev/null +++ b/exercises/087_async4.zig @@ -0,0 +1,30 @@ +// +// It has probably not escaped your attention that we are no +// longer capturing a return value from foo() because the 'async' +// keyword returns the frame instead. +// +// One way to solve this is to use a global variable. +// +// See if you can make this program print "1 2 3 4 5". +// +const print = @import("std").debug.print; + +var global_counter: i32 = 0; + +pub fn main() void { + var foo_frame = async foo(); + + while (global_counter <= 5) { + print("{} ", .{global_counter}); + ??? + } + + print("\n", .{}); +} + +fn foo() void { + while (true) { + ??? + ??? + } +} diff --git a/patches/patches/087_async4.patch b/patches/patches/087_async4.patch new file mode 100644 index 0000000..9ea5012 --- /dev/null +++ b/patches/patches/087_async4.patch @@ -0,0 +1,10 @@ +19c19 +< ??? +--- +> resume foo_frame; +27,28c27,28 +< ??? +< ??? +--- +> global_counter += 1; +> suspend; |