zig/test/cases/coroutines.zig
Andrew Kelley 36eadb569a run coroutine tests only in Debug mode
LLVM 5.0.1, 6.0.0, and trunk crash when attempting to optimize coroutine code.
So, Zig does not support ReleaseFast or ReleaseSafe for coroutines yet.
Luckily, Clang users are running into the same crashes, so folks from the LLVM
community are working on fixes. If we're really lucky they'll be fixed in 6.0.1.
Otherwise we can hope for 7.0.0.
2018-02-28 18:56:26 -05:00

17 lines
300 B
Zig

const std = @import("std");
const assert = std.debug.assert;
var x: i32 = 1;
test "create a coroutine and cancel it" {
const p = try (async(std.debug.global_allocator) simpleAsyncFn());
cancel p;
assert(x == 2);
}
async fn simpleAsyncFn() void {
x += 1;
suspend;
x += 1;
}