Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function asyncForEach(array, callback) {
- for (let index = 0; index < array.length; index++) {
- await callback(array[index], index, array);
- }
- }
- async function asyncForEachByFour(array, callback) {
- for (let index = 0; index < array.length; index += 4) {
- const asyncArr = [];
- for (let j = index; j < index + 4 && j < array.length; j++) {
- asyncArr.push(callback(array[j], j, array))
- }
- await Promise.all(asyncArr);
- }
- }
- async function asyncQueues(
- array: string[],
- callback: (address: string) => Promise<void>,
- numQueues: number,
- ) {
- const queues: Record<string, string[]> = {}
- for (let index = 0; index < array.length; index += numQueues) {
- for (let j = 0; j < numQueues && j + index < array.length; j++) {
- queues[j] = queues[j] || []
- queues[j].push(array[j + index])
- }
- }
- await Promise.all(Object.values(queues).map(async arr => {
- for (const a of arr) {
- await callback(a)
- }
- }))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement