authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-30 13:07:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-30 13:07:04-04:00
logcfe03c764de0d2edfbad74a71d7c18f0fd68b506
tree0aa391152b43f52e3095a22fb09caaa2d39be3c9
parentc91c781952bd9750c029a48d0dd7a5a24ec089cf

fix docs for break from suspend


1 files changed, 6 insertions(+), 6 deletions(-)

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