aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-07-21 23:27:47 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-07-21 23:27:47 -0400
commit59bf9ca58c992e02423fae2ba8773eac098189b9 (patch)
tree742f097934f954997e70bfd13b3911013a80f141 /test
parent11bd50f2b2a74ce25d841a15ba67d042d41b71c2 (diff)
downloadzig-59bf9ca58c992e02423fae2ba8773eac098189b9.tar.gz
zig-59bf9ca58c992e02423fae2ba8773eac098189b9.zip
implement async function parameters
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/coroutines.zig37
1 files changed, 19 insertions, 18 deletions
diff --git a/test/stage1/behavior/coroutines.zig b/test/stage1/behavior/coroutines.zig
index fd07790e7f..3a54657020 100644
--- a/test/stage1/behavior/coroutines.zig
+++ b/test/stage1/behavior/coroutines.zig
@@ -2,33 +2,34 @@ const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
-var x: i32 = 1;
+var global_x: i32 = 1;
test "simple coroutine suspend and resume" {
const p = async simpleAsyncFn();
- expect(x == 2);
+ expect(global_x == 2);
resume p;
- expect(x == 3);
+ expect(global_x == 3);
}
fn simpleAsyncFn() void {
- x += 1;
+ global_x += 1;
suspend;
- x += 1;
+ global_x += 1;
}
-//test "create a coroutine and cancel it" {
-// const p = try async<allocator> simpleAsyncFn();
-// comptime expect(@typeOf(p) == promise->void);
-// cancel p;
-// expect(x == 2);
-//}
-//async fn simpleAsyncFn() void {
-// x += 1;
-// suspend;
-// x += 1;
-//}
-//
-//test "coroutine suspend, resume, cancel" {
+var global_y: i32 = 1;
+
+test "pass parameter to coroutine" {
+ const p = async simpleAsyncFnWithArg(2);
+ expect(global_y == 3);
+ resume p;
+ expect(global_y == 5);
+}
+fn simpleAsyncFnWithArg(delta: i32) void {
+ global_y += delta;
+ suspend;
+ global_y += delta;
+}
+//test "coroutine suspend, resume" {
// seq('a');
// const p = try async<allocator> testAsyncSeq();
// seq('c');