Skip to content

Commit

Permalink
Revert "feat(Collector): allow collectors to be consumed by for-await…
Browse files Browse the repository at this point in the history
…-of loops (discordjs#3269)"

This reverts commit f913c26.
  • Loading branch information
samsamson33 committed Feb 27, 2020
1 parent 7563592 commit 60e1851
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 32 deletions.
31 changes: 0 additions & 31 deletions src/structures/interfaces/Collector.js
Expand Up @@ -196,37 +196,6 @@ class Collector extends EventEmitter {
if (reason) this.stop(reason);
}

/**
* Allows collectors to be consumed with for-await-of loops
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of}
*/
async *[Symbol.asyncIterator]() {
const queue = [];
const onCollect = item => queue.push(item);
this.on('collect', onCollect);

try {
while (queue.length || !this.ended) {
if (queue.length) {
yield queue.shift();
} else {
// eslint-disable-next-line no-await-in-loop
await new Promise(resolve => {
const tick = () => {
this.off('collect', tick);
this.off('end', tick);
return resolve();
};
this.on('collect', tick);
this.on('end', tick);
});
}
}
} finally {
this.off('collect', onCollect);
}
}

toJSON() {
return Util.flatten(this);
}
Expand Down
1 change: 0 additions & 1 deletion typings/index.d.ts
Expand Up @@ -363,7 +363,6 @@ declare module 'discord.js' {
public handleCollect(...args: any[]): void;
public handleDispose(...args: any[]): void;
public stop(reason?: string): void;
public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
public toJSON(): object;

protected listener: Function;
Expand Down

0 comments on commit 60e1851

Please sign in to comment.