Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canceling a coroutine leads to defers not executed #1259

Closed
andrewrk opened this issue Jul 18, 2018 · 0 comments · Fixed by #1307
Closed

canceling a coroutine leads to defers not executed #1259

andrewrk opened this issue Jul 18, 2018 · 0 comments · Fixed by #1307
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@andrewrk
Copy link
Member

const std = @import("std");

var defer1: bool = false;
var defer2: bool = false;

test "aoeu" {
    _ = async<std.debug.global_allocator> asyncTest() catch unreachable;
    std.debug.assert(defer1);
    std.debug.assert(defer2);
}

async fn asyncTest() void {
    defer {
        defer1 = true;
    }
    await (async baz() catch unreachable);
}

var bar_handle: promise = undefined;

async fn baz() void {
    const foo_handle = async foo() catch unreachable;
    resume bar_handle;
    cancel bar_handle;
    defer {
        defer2 = true;
    }
    const value = await foo_handle;
    @panic("unreachable");
}

async fn foo() i32 {
    await (async bar() catch unreachable);
    return 1234;
}

async fn bar() void {
    suspend |p| {
        bar_handle = p;
    }
    suspend;
}
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jul 18, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant