mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Collector): yield all collected values (#7073)
This commit is contained in:
@@ -236,7 +236,7 @@ class Collector extends EventEmitter {
|
||||
*/
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const queue = [];
|
||||
const onCollect = item => queue.push(item);
|
||||
const onCollect = (...item) => queue.push(item);
|
||||
this.on('collect', onCollect);
|
||||
|
||||
try {
|
||||
|
||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -670,7 +670,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
||||
public handleDispose(...args: unknown[]): Promise<void>;
|
||||
public stop(reason?: string): void;
|
||||
public resetTimer(options?: CollectorResetTimerOptions): void;
|
||||
public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
|
||||
public [Symbol.asyncIterator](): AsyncIterableIterator<[V, ...F]>;
|
||||
public toJSON(): unknown;
|
||||
|
||||
protected listener: (...args: any[]) => void;
|
||||
|
||||
@@ -794,11 +794,23 @@ messageCollector.on('collect', (...args) => {
|
||||
expectType<[Message]>(args);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
for await (const value of messageCollector) {
|
||||
expectType<[Message<boolean>]>(value);
|
||||
}
|
||||
})();
|
||||
|
||||
declare const reactionCollector: ReactionCollector;
|
||||
reactionCollector.on('dispose', (...args) => {
|
||||
expectType<[MessageReaction, User]>(args);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
for await (const value of reactionCollector) {
|
||||
expectType<[MessageReaction, User]>(value);
|
||||
}
|
||||
})();
|
||||
|
||||
// Make sure the properties are typed correctly, and that no backwards properties
|
||||
// (K -> V and V -> K) exist:
|
||||
expectType<'messageCreate'>(Constants.Events.MESSAGE_CREATE);
|
||||
@@ -1169,6 +1181,12 @@ collector.on('end', (collection, reason) => {
|
||||
expectType<string>(reason);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
for await (const value of collector) {
|
||||
expectType<[Interaction, ...string[]]>(value);
|
||||
}
|
||||
})();
|
||||
|
||||
expectType<Promise<number | null>>(shard.eval(c => c.readyTimestamp));
|
||||
|
||||
// Test audit logs
|
||||
|
||||
Reference in New Issue
Block a user