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

fix: debounceTime with asapScheduler deadlock because of nested calls #7207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/internal/scheduler/AsapScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { AsyncScheduler } from './AsyncScheduler';
export class AsapScheduler extends AsyncScheduler {
public flush(action?: AsyncAction<any>): void {
this._active = true;

const { actions } = this;
let error: any;
action = action || actions.shift()!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
action = action || actions.shift()!;
action = action ?? actions.shift()!;


// The async id that effects a call to flush is stored in _scheduled.
// But in case of nested asyncScheduler calls _scheduled could be cleared,
// so we take flushId from the first action to guarantee execution of all
// actions with the same id.
// Before executing an action, it's necessary to check the action's async
// id to determine whether it's supposed to be executed in the current
// flush.
Expand All @@ -13,13 +21,9 @@ export class AsapScheduler extends AsyncScheduler {
// are removed from the actions array and that can shift actions that are
// scheduled to be executed in a subsequent flush into positions at which
// they are executed within the current flush.
const flushId = this._scheduled;
const flushId = this._scheduled ?? action.id;
this._scheduled = undefined;

const { actions } = this;
let error: any;
action = action || actions.shift()!;

do {
if ((error = action.execute(action.state, action.delay))) {
break;
Expand Down