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

Cancellable interface #104

Open
SOF3 opened this issue Nov 24, 2021 · 0 comments
Open

Cancellable interface #104

SOF3 opened this issue Nov 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@SOF3
Copy link
Owner

SOF3 commented Nov 24, 2021

I don't know if "cancel" is a good term; I am not even sure if cancellation is a correct thing to do in a promise framework, where promise is just a state machine (unlike Rust futures, where you need to await a future to actually execute it).

Design

function read_line_await(LineBufReader $reader) {
    $resolve = yield Await::RESOLVE;
    $isCancelled = yield Await::IS_CANCEL;
    $reader->shiftLineCallback(function($line) use($isCancelled, $resolve) {
        if($isCancelled()) {
            $reader->unshiftLine($line);
        } else {
            $resolve($line);
        }
    });
}

When we Await::race multiple generators, the losing generators are set to be cancelled

Concerns

Coroutines are not necessarily cancellatoin-aware. They need to explicitly indicate what they do when they are cancelled (in particular, stateful promises need to reset the states they changed), which is a usability issue.

@SOF3 SOF3 added the enhancement New feature or request label Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant