Skip to content

Instantly share code, notes, and snippets.

@emekoi
Created October 23, 2019 01:51
Show Gist options
  • Save emekoi/4d12b6ea14d30a291716e53057b458b8 to your computer and use it in GitHub Desktop.
Save emekoi/4d12b6ea14d30a291716e53057b458b8 to your computer and use it in GitHub Desktop.
const std = @import("std");
// outputs:
// from foo
// from bar
fn foo() void {
suspend {
_ = bar(@frame());
}
std.debug.warn("from foo\n");
}
fn bar(frame: anyframe) void {
resume frame;
std.debug.warn("from bar\n");
}
test "test" {
_ = async foo();
}
@andrewrk
Copy link

    _ = async foo();
        _ = bar(@frame()); // tail call; bar() will return to foo's caller (test "test")
    resume frame;
    std.debug.warn("from foo\n"); // then return from foo() to bar()
    std.debug.warn("from bar\n"); // then return from bar() to test "test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment