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

Debug mode #97

Open
jeswr opened this issue Mar 8, 2023 · 0 comments
Open

Debug mode #97

jeswr opened this issue Mar 8, 2023 · 0 comments

Comments

@jeswr
Copy link
Collaborator

jeswr commented Mar 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant