| ... | ... | @@ -4665,24 +4665,24 @@ async fn testSuspendBlock() void { |
| 4665 | 4665 | block, while the old thread continued executing the suspend block. |
| 4666 | 4666 | </p> |
| 4667 | 4667 | <p> |
| 4668 | | However, if you use labeled <code>break</code> on the suspend block, the coroutine |
| 4668 | However, the coroutine can be directly resumed from the suspend block, in which case it |
| 4669 | 4669 | never returns to its resumer and continues executing. |
| 4670 | 4670 | </p> |
| 4671 | 4671 | {#code_begin|test#} |
| 4672 | 4672 | const std = @import("std"); |
| 4673 | 4673 | const assert = std.debug.assert; |
| 4674 | 4674 | |
| 4675 | | test "break from suspend" { |
| 4675 | test "resume from suspend" { |
| 4676 | 4676 | var buf: [500]u8 = undefined; |
| 4677 | 4677 | var a = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator; |
| 4678 | 4678 | var my_result: i32 = 1; |
| 4679 | | const p = try async<a> testBreakFromSuspend(&my_result); |
| 4679 | const p = try async<a> testResumeFromSuspend(&my_result); |
| 4680 | 4680 | cancel p; |
| 4681 | 4681 | std.debug.assert(my_result == 2); |
| 4682 | 4682 | } |
| 4683 | | async fn testBreakFromSuspend(my_result: *i32) void { |
| 4684 | | s: suspend |p| { |
| 4685 | | break :s; |
| 4683 | async fn testResumeFromSuspend(my_result: *i32) void { |
| 4684 | suspend |p| { |
| 4685 | resume p; |
| 4686 | 4686 | } |
| 4687 | 4687 | my_result.* += 1; |
| 4688 | 4688 | suspend; |