Skip to content

Scheduler.flush throws unclear error when actions is empty (cannot read property 'execute' of undefined) #4690

Closed
@notnarb

Description

@notnarb

Bug Report

Current Behavior
Calling .flush() on a scheduler (e.g. animationFrameScheduler) with no pending actions causes an unclear exception to be thrown:

TypeError: Cannot read property 'execute' of undefined
at AnimationFrameScheduler.flush (https://rxjs-pc1ga8.stackblitz.io/turbo_modules/rxjs@6.4.0/internal/scheduler/AnimationFrameScheduler.js:31:32)
at Object.eval (https://rxjs-pc1ga8.stackblitz.io/~/index.ts:12:36)
at eval (https://rxjs-pc1ga8.stackblitz.io/~/index.ts:19:4)
at eval (https://rxjs-pc1ga8.stackblitz.io/~/index.ts:20:3)
at eval (<anonymous>)
at Qt (https://c.staticblitz.com/d/webcontainer.e1e926a8972546110c3.js:15:30145)
at https://c.staticblitz.com/d/webcontainer.e1e926a8972546110c3.js:15:38799
at U (https://c.staticblitz.com/d/webcontainer.e1e926a8972546110c3.js:15:13565)
at https://c.staticblitz.com/d/webcontainer.e1e926a8972546110c3.js:15:13207
at boot (https://rxjs-pc1ga8.stackblitz.io/dev/boot:6:3)

Reproduction

import {animationFrameScheduler} from 'rxjs';
animationFrameScheduler.flush();

Expected behavior
Either one of:

  • not throwing when there are no pending actions
  • throwing a clearer error (e.g. 'Attempting to flush an empty queue')

Environment

  • Runtime: Chrome v73
  • RxJS version: 6.4.x

Possible Solution

See expected behavior. This appears to affect all schedulers that have this do while loop without verifying that a valid action has been shift'd off of this.actions

This may be working as intended (and no change desired for performance reasons) in which case just having this issue open and google-able would provide additional documentation

Additional context/Screenshots

#2697 Appears to have been the same issue given their stacktrace: https://github.com/ReactiveX/rxjs/blob/5.4.1/src/scheduler/AsapScheduler.ts#L17

A clearer error (or no error at all) would probably have pointed them in the right direction.


Happy to submit a fix myself if the desired behavior is defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions