Skip to content

Commit

Permalink
add heap allocated async function frame test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Aug 2, 2019
1 parent b3b6a98 commit 5bd330e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/stage1/behavior/coroutines.zig
Expand Up @@ -333,3 +333,27 @@ async fn testBreakFromSuspend(my_result: *i32) void {
suspend;
my_result.* += 1;
}

test "heap allocated async function frame" {
const S = struct {
var x: i32 = 42;

fn doTheTest() !void {
const frame = try std.heap.direct_allocator.create(@Frame(someFunc));
defer std.heap.direct_allocator.destroy(frame);

expect(x == 42);
frame.* = async someFunc();
expect(x == 43);
resume frame;
expect(x == 44);
}

fn someFunc() void {
x += 1;
suspend;
x += 1;
}
};
try S.doTheTest();
}

0 comments on commit 5bd330e

Please sign in to comment.