async forEach
This commit is contained in:
parent
d2a461b904
commit
f2c1fa5f12
1 changed files with 14 additions and 1 deletions
|
|
@ -238,6 +238,18 @@ const currHandshakeAddress = async userPub => {
|
||||||
return typeof maybeAddr === 'string' ? maybeAddr : null
|
return typeof maybeAddr === 'string' ? maybeAddr : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {T[]} arr
|
||||||
|
* @param {(item: T) => void} cb
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const asyncForEach = async (arr, cb) => {
|
||||||
|
const promises = arr.map(item => cb(item))
|
||||||
|
|
||||||
|
await Promise.all(promises)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T
|
* @template T
|
||||||
* @template U
|
* @template U
|
||||||
|
|
@ -319,5 +331,6 @@ module.exports = {
|
||||||
tryAndWait,
|
tryAndWait,
|
||||||
mySecret,
|
mySecret,
|
||||||
promisifyGunNode: require('./promisifygun'),
|
promisifyGunNode: require('./promisifygun'),
|
||||||
didDisconnect
|
didDisconnect,
|
||||||
|
asyncForEach
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue