summaryrefslogtreecommitdiffstatshomepage
path: root/exercises/087_async4.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-05-12 21:36:57 -0400
committerDave Gauer <dave@ratfactor.com>2021-05-12 21:36:57 -0400
commitbe279c78f5623bc7785f9a8a3f900700d481be15 (patch)
treeb4a2bc00bed7ea92c6f248eded363ce6b9479687 /exercises/087_async4.zig
parent3e5647d88cde9834dea4a71088cf63413f859f4e (diff)
add ex087 async 4
Diffstat (limited to 'exercises/087_async4.zig')
-rw-r--r--exercises/087_async4.zig30
1 files changed, 30 insertions, 0 deletions
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) {
+ ???
+ ???
+ }
+}