091_async8.zig 587 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // You have doubtless noticed that 'suspend' requires a block
  3. // expression like so:
  4. //
  5. // suspend {}
  6. //
  7. // The suspend block executes when a function suspends. To get
  8. // sense for when this happens, please make the following
  9. // program print the string
  10. //
  11. // "ABCDEF"
  12. //
  13. const print = @import("std").debug.print;
  14. pub fn main() void {
  15. print("A", .{});
  16. var frame = async suspendable();
  17. print("X", .{});
  18. resume frame;
  19. print("F", .{});
  20. }
  21. fn suspendable() void {
  22. print("X", .{});
  23. suspend {
  24. print("X", .{});
  25. }
  26. print("X", .{});
  27. }