Skip to content

Debug mode #97

@jeswr

Description

@jeswr

Per @rubensworks comment comunica/comunica#1165 (comment); it would be useful to have a debug mode for asynciterator.

The most straightforward approach would look something like

const iterators = [];

process.on('exit', () => {
  if (iterators.filter(iter => !iter.done).length > 0) {
     console.warn("found open iterators on process exit");
  }
})


export class AsyncIterator<T> extends EventEmitter {
  protected _state: number;
  private _readable = false;
  protected _properties?: { [name: string]: any };
  protected _propertyCallbacks?: { [name: string]: [(value: any) => void] };

  /** Creates a new `AsyncIterator`. */
  constructor(initialState = OPEN) {
    super();
    this._state = initialState;
    iterators.push(this)
    this.on('newListener', waitForDataListener);
  }

However, this approach doesn't work with jest as the exit event is not emitted after the test suites have run.

Note that we could also offer some jest specific functionality that checks for iterators that are not closed on the afterEach call back. The benefit there is that you can see specifically which tests are leaving iterators open in a test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions