Merge pull request #111 from DjDeveloperr/main

add Async Interator support for Managers
This commit is contained in:
Helloyunho 2021-02-26 19:33:39 +09:00 committed by GitHub
commit 9cd9eb9c6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -60,6 +60,13 @@ export class BaseManager<T, T2> {
return collection
}
async *[Symbol.asyncIterator](): AsyncIterableIterator<T2> {
const arr = (await this.array()) ?? []
const { readable, writable } = new TransformStream()
arr.forEach((el) => writable.getWriter().write(el))
yield* readable.getIterator()
}
/** Deletes everything from Cache */
flush(): any {
return this.client.cache.deleteCache(this.cacheName)

View file

@ -39,4 +39,11 @@ export class BaseChildManager<T, T2> {
}
return collection
}
async *[Symbol.asyncIterator](): AsyncIterableIterator<T2> {
const arr = (await this.array()) ?? []
const { readable, writable } = new TransformStream()
arr.forEach((el: unknown) => writable.getWriter().write(el))
yield* readable.getIterator()
}
}

View file

@ -227,6 +227,13 @@ client.on('messageCreate', async (msg: Message) => {
})
await msg.member?.roles.add(role)
}
} else if (msg.content === '!roles') {
let buf = 'Roles:'
if (msg.member === undefined) return
for await (const role of msg.member.roles) {
buf += `\n${role.name}`
}
msg.reply(buf)
}
})