087_async4.zig 600 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // It has probably not escaped your attention that we are no
  3. // longer capturing a return value from foo() because the 'async'
  4. // keyword returns the frame instead.
  5. //
  6. // One way to solve this is to use a global variable.
  7. //
  8. // See if you can make this program print "1 2 3 4 5".
  9. //
  10. const print = @import("std").debug.print;
  11. var global_counter: i32 = 0;
  12. pub fn main() void {
  13. var foo_frame = async foo();
  14. while (global_counter <= 5) {
  15. print("{} ", .{global_counter});
  16. ???
  17. }
  18. print("\n", .{});
  19. }
  20. fn foo() void {
  21. while (true) {
  22. ???
  23. ???
  24. }
  25. }