Skip to content

canceling a coroutine leads to defers not executed #1259

@andrewrk

Description

@andrewrk
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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions