add AsyncInterator support for Managers
This commit is contained in:
		
							parent
							
								
									30fa9429c5
								
							
						
					
					
						commit
						00dae42f7b
					
				
					 3 changed files with 21 additions and 0 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
|  | @ -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() | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -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) | ||||
|   } | ||||
| }) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue