From 3e5647d88cde9834dea4a71088cf63413f859f4e Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Wed, 12 May 2021 21:25:48 -0400 Subject: add ex086 async 3 --- exercises/086_async3.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 exercises/086_async3.zig (limited to 'exercises') diff --git a/exercises/086_async3.zig b/exercises/086_async3.zig new file mode 100644 index 0000000..ae5a9a6 --- /dev/null +++ b/exercises/086_async3.zig @@ -0,0 +1,29 @@ +// +// Because they can suspend and resume, async Zig functions are +// an example of a more general programming concept called +// "coroutines". One of the neat things about Zig async functions +// is that they retain their state as they are suspended and +// resumed. +// +// See if you can make this program print "5 4 3 2 1". +// +const print = @import("std").debug.print; + +pub fn main() void { + const n = 5; + var foo_frame = async foo(n); + + ??? + + print("\n", .{}); +} + +fn foo(countdown: u32) void { + var current = countdown; + + while (current > 0) { + print("{} ", .{current}); + current -= 1; + suspend; + } +} -- cgit v1.2.3-70-g09d2