| ... | ... | @@ -6594,13 +6594,11 @@ const std = @import("std"); |
| 6594 | 6594 | const expect = std.testing.expect; |
| 6595 | 6595 | |
| 6596 | 6596 | test "async and await" { |
| 6597 | | // Here we have an exception where we do not match an async |
| 6598 | | // with an await. The test block is not async and so cannot |
| 6599 | | // have a suspend point in it. |
| 6600 | | // This is well-defined behavior, and everything is OK here. |
| 6601 | | // Note however that there would be no way to collect the |
| 6602 | | // return value of amain, if it were something other than void. |
| 6603 | | _ = async amain(); |
| 6597 | // The test block is not async and so cannot have a suspend |
| 6598 | // point in it. By using the nosuspend keyword, we promise that |
| 6599 | // the code in amain will finish executing without suspending |
| 6600 | // back to the test block. |
| 6601 | nosuspend amain(); |
| 6604 | 6602 | } |
| 6605 | 6603 | |
| 6606 | 6604 | fn amain() void { |
| ... | ... | @@ -10799,9 +10797,16 @@ fn readU32Be() u32 {} |
| 10799 | 10797 | <pre>{#syntax#}nosuspend{#endsyntax#}</pre> |
| 10800 | 10798 | </td> |
| 10801 | 10799 | <td> |
| 10802 | | The {#syntax#}nosuspend{#endsyntax#} keyword. |
| 10800 | The {#syntax#}nosuspend{#endsyntax#} keyword can be used in front of a block, statement or expression, to mark a scope where no suspension points are reached. |
| 10801 | In particular, inside a {#syntax#}nosuspend{#endsyntax#} scope: |
| 10802 | <ul> |
| 10803 | <li>Using the {#syntax#}suspend{#endsyntax#} keyword results in a compile error.</li> |
| 10804 | <li>Using {#syntax#}await{#endsyntax#} on a function frame which hasn't completed yet results in safety-checked {#link|Undefined Behavior#}.</li> |
| 10805 | <li>Calling an async function may result in safety-checked {#link|Undefined Behavior#}, because it's equivalent to <code>await async some_async_fn()</code>, which contains an {#syntax#}await{#endsyntax#}.</li> |
| 10806 | </ul> |
| 10807 | Code inside a {#syntax#}nosuspend{#endsyntax#} scope does not cause the enclosing function to become an {#link|async function|Async Functions#}. |
| 10803 | 10808 | <ul> |
| 10804 | | <li>TODO add documentation for nosuspend</li> |
| 10809 | <li>See also {#link|Async Functions#}</li> |
| 10805 | 10810 | </ul> |
| 10806 | 10811 | </td> |
| 10807 | 10812 | </tr> |