085_async2.zig 683 B

12345678910111213141516171819202122232425262728
  1. //
  2. // So, 'suspend' returns control to the place from which it was
  3. // called (the "call site"). How do we give control back to the
  4. // suspended function?
  5. //
  6. // For that, we have a new keyword called 'resume' which takes an
  7. // async function invocation's frame and returns control to it.
  8. //
  9. // fn fooThatSuspends() void {
  10. // suspend {}
  11. // }
  12. //
  13. // var foo_frame = async fooThatSuspends();
  14. // resume foo_frame;
  15. //
  16. // See if you can make this program print "Hello async!".
  17. //
  18. const print = @import("std").debug.print;
  19. pub fn main() void {
  20. var foo_frame = async foo();
  21. }
  22. fn foo() void {
  23. print("Hello ", .{});
  24. suspend {}
  25. print("async!\n", .{});
  26. }