aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/exercises/085_async2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-05-12 21:04:58 -0400
committerDave Gauer <dave@ratfactor.com>2021-05-12 21:04:58 -0400
commit54c048b0a0ea5ee2136c4d4193660d4934eab925 (patch)
treeba1104262010622fc7ea1b2af393d5a149bca34b /exercises/085_async2.zig
parent3b0876153249362356166ea41ddb5241f4a5171f (diff)
add ex085 async 2
Diffstat (limited to 'exercises/085_async2.zig')
-rw-r--r--exercises/085_async2.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/exercises/085_async2.zig b/exercises/085_async2.zig
new file mode 100644
index 0000000..0ca322e
--- /dev/null
+++ b/exercises/085_async2.zig
@@ -0,0 +1,29 @@
+//
+// So, 'suspend' returns control to the place from which it was
+// called (the "call site"). How do we control back to the
+// suspended function?
+//
+// For that, we have a new keyword called 'resume' which takes an
+// async function invocation's frame and returns control to it.
+//
+// fn fooThatSuspends() void {
+// suspend;
+// }
+//
+// var foo_frame = async fooThatSuspends();
+// resume foo_frame;
+//
+// See if you can make this program print "Hello async!".
+//
+const print = @import("std").debug.print;
+
+pub fn main() void {
+ var foo_frame = async foo();
+}
+
+fn foo() void {
+ print("Hello ", .{});
+ suspend;
+ print("async!\n", .{});
+}
+