2018-03-01 07:22:43 +08:00
|
|
|
const std = @import("std");
|
|
|
|
const assert = std.debug.assert;
|
|
|
|
|
|
|
|
var x: i32 = 1;
|
|
|
|
|
|
|
|
test "create a coroutine and cancel it" {
|
2018-03-01 07:56:26 +08:00
|
|
|
const p = try (async(std.debug.global_allocator) simpleAsyncFn());
|
2018-03-01 07:22:43 +08:00
|
|
|
cancel p;
|
|
|
|
assert(x == 2);
|
|
|
|
}
|
|
|
|
|
2018-03-01 07:56:26 +08:00
|
|
|
async fn simpleAsyncFn() void {
|
2018-03-01 07:22:43 +08:00
|
|
|
x += 1;
|
|
|
|
suspend;
|
|
|
|
x += 1;
|
|
|
|
}
|