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

safety assertion for resuming a coroutine which is awaiting #1163

Closed
andrewrk opened this issue Jun 27, 2018 · 1 comment
Closed

safety assertion for resuming a coroutine which is awaiting #1163

andrewrk opened this issue Jun 27, 2018 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@andrewrk
Copy link
Member

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.

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Jun 27, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Jun 27, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 19, 2019
@andrewrk
Copy link
Member Author

Done with the merge of #3033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

No branches or pull requests

1 participant