diff options
-rw-r--r-- | README.md | 49 | ||||
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | exercises/091_async8.zig | 35 | ||||
-rw-r--r-- | patches/patches/091_async8.patch | 16 |
4 files changed, 73 insertions, 31 deletions
@@ -111,16 +111,11 @@ to zig-cache/bin with: zig build 19_install ``` -## TODO +## What's Covered -Contributions are very welcome! I'm writing this to teach myself and to create -the learning resource I wished for. There will be tons of room for improvement: - -* Wording of explanations -* Idiomatic usage of Zig -* Additional exercises - -Planned exercises: +I've decide to limit Ziglings to the core language and not +attempt coverage of the Standard Library. Perhaps you can change +my mind? Core Language @@ -154,25 +149,17 @@ Core Language * [x] Sentinel termination * [x] Quoted identifiers @"" * [x] Anonymous structs/tuples/lists -* [ ] Async -* [ ] Working with C? - -Modules and the Zig Standard Library - -* [ ] Imports -* [ ] Allocators -* [ ] Arraylist -* [ ] Filesystem -* [ ] Readers and Writers -* [ ] Formatting -* [ ] Random Numbers -* [ ] Crypto -* [ ] Threads -* [ ] Hash Maps -* [ ] Stacks -* [ ] Sorting -* [ ] Iterators - -The initial topics for these exercises were unabashedly cribbed from -[ziglearn.org](https://ziglearn.org/). I've since moved things around -in an order that I think best lets each topic build upon each other. +* [ ] Async <--- IN PROGRESS! + +## Contributing + +Contributions are very welcome! I'm writing this to teach myself and to create +the learning resource I wished for. There will be tons of room for improvement: + +* Wording of explanations +* Idiomatic usage of Zig +* Maybe additional exercises? + +Please see CONTRIBUTING.md in this repo for the full details. + + @@ -443,6 +443,10 @@ const exercises = [_]Exercise{ .main_file = "090_async7.zig", .output = "beef? BEEF!", }, + .{ + .main_file = "091_async8.zig", + .output = "ABCDEF", + }, }; /// Check the zig version to make sure it can compile the examples properly. 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", .{}); +} diff --git a/patches/patches/091_async8.patch b/patches/patches/091_async8.patch new file mode 100644 index 0000000..8a93b31 --- /dev/null +++ b/patches/patches/091_async8.patch @@ -0,0 +1,16 @@ +20c20 +< print("X", .{}); +--- +> print("D", .{}); +28c28 +< print("X", .{}); +--- +> print("B", .{}); +31c31 +< print("X", .{}); +--- +> print("C", .{}); +34c34 +< print("X", .{}); +--- +> print("E", .{}); |