Skip to content

safety assertion for resuming a coroutine which is awaiting #1163

@andrewrk

Description

@andrewrk
const std = @import("std");
const assert = std.debug.assert;

var await_a_promise: promise = undefined;
var await_final_result: i32 = 0;

test "coroutine await" {
    const p = async<std.debug.global_allocator> await_amain() catch unreachable;
    resume p;
}
async fn await_amain() void {
    const p = async await_another() catch unreachable;
    const result = await p;
    assert(result == 1234);
}
async fn await_another() i32 {
    suspend |p| {
        await_a_promise = p;
    }
    return 1234;
}

Here the assertion fails because the resume causes the await to complete improperly. The await should complete only after await_another returns.

Zig should have a runtime safety assertion when you resume a coroutine which is suspended in the await state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions