-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Wrong behavior of async*
function after pause-resume-pause
#49465
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
Comments
async*
function after pause-resume-pause
/cc @alexmarkov |
Calling
The spec doesn't clarify what happens if subscription is resumed but paused again before async* generator has a chance to run. Maybe we should update the spec to explicitly mention that yield/yield* should check if the subscription is paused and canceled both when entering yield/yield* and right before resuming the execution of async* function. @lrhn Could you confirm that we need the 2nd check for the paused subscription immediately before resuming the async* body? |
That was deliberate. So the current behavior is valid and within specification. The spec should say what is required:
Technically, the VM only needs to check for cancellation once: After checking for/resuming from a pause. The minimal implementation will be:
I usually write it as: StreamController<T> $c = ...
Completer<void>? _suspendedAtYield;
$c.onCancel = $c.onResume = () {
_suspendedAtYield?.complete(null);
_suspendedAtYield = null;
};
....
// `yield e` becomes:
$c.add(e);
if ($c.isPaused) {
await (_suspendedAtYield = Completer()).future;
}
if (!$c.hasListener) return;
With the current synchronous |
Generator function marked as
async*
performs excessive generation cicle afterresume()
Example:
Tested on the edge version of SDK on Linux
Cc @lrhn
The text was updated successfully, but these errors were encountered: