summaryrefslogtreecommitdiff
path: root/exercises/091_async8.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-11-07 20:51:33 -0500
committerDave Gauer <dave@ratfactor.com>2021-11-07 20:51:33 -0500
commit49ce260748a54d6737be1a2407c2f5377f175339 (patch)
tree7d02121611582d9beb4e5c6c04edbc5bc581400c /exercises/091_async8.zig
parent4c7eebbbfca3337b5e3af33eb34979dc56716178 (diff)
Added ex91 - closing in on async!
Diffstat (limited to 'exercises/091_async8.zig')
-rw-r--r--exercises/091_async8.zig35
1 files changed, 35 insertions, 0 deletions
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", .{});
+}