add test for coroutine suspend with block

master
Andrew Kelley 2018-02-28 22:26:26 -05:00
parent 8429d4ceac
commit 834e992a7c
1 changed files with 18 additions and 0 deletions

View File

@ -41,3 +41,21 @@ fn seq(c: u8) void {
points[index] = c;
index += 1;
}
test "coroutine suspend with block" {
const p = (async(std.debug.global_allocator) testSuspendBlock()) catch unreachable;
std.debug.assert(!result);
resume a_promise;
std.debug.assert(result);
cancel p;
}
var a_promise: promise = undefined;
var result = false;
async fn testSuspendBlock() void {
suspend |p| {
a_promise = p;
}
result = true;
}