diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-05-12 21:04:58 -0400 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-05-12 21:04:58 -0400 |
commit | d8dddd128fdb3e7d0f36c60c522a56cbcd64bc22 (patch) | |
tree | ba1104262010622fc7ea1b2af393d5a149bca34b | |
parent | e555fdc3dfbc7f0f7654ab5d530a0a1d8f0d628e (diff) | |
download | ziglings-d8dddd128fdb3e7d0f36c60c522a56cbcd64bc22.tar.gz ziglings-d8dddd128fdb3e7d0f36c60c522a56cbcd64bc22.tar.bz2 ziglings-d8dddd128fdb3e7d0f36c60c522a56cbcd64bc22.tar.xz ziglings-d8dddd128fdb3e7d0f36c60c522a56cbcd64bc22.zip |
add ex085 async 2
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | exercises/085_async2.zig | 29 | ||||
-rw-r--r-- | patches/patches/085_async2.patch | 2 |
3 files changed, 35 insertions, 0 deletions
@@ -418,6 +418,10 @@ const exercises = [_]Exercise{ .output = "foo() A", .hint = "Read the facts. Use the facts.", }, + .{ + .main_file = "085_async2.zig", + .output = "Hello async!", + }, }; /// Check the zig version to make sure it can compile the examples properly. 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", .{}); +} + diff --git a/patches/patches/085_async2.patch b/patches/patches/085_async2.patch new file mode 100644 index 0000000..cc71293 --- /dev/null +++ b/patches/patches/085_async2.patch @@ -0,0 +1,2 @@ +21a22 +> resume foo_frame; |