From f2c1fa5f128826c2a96c57f4f44eb629bcf6a8a3 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 25 Jan 2020 18:19:45 -0400 Subject: [PATCH] async forEach --- services/gunDB/contact-api/utils/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 6a393f8a..8c749f12 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -238,6 +238,18 @@ const currHandshakeAddress = async userPub => { return typeof maybeAddr === 'string' ? maybeAddr : null } +/** + * @template T + * @param {T[]} arr + * @param {(item: T) => void} cb + * @returns {Promise} + */ +const asyncForEach = async (arr, cb) => { + const promises = arr.map(item => cb(item)) + + await Promise.all(promises) +} + /** * @template T * @template U @@ -319,5 +331,6 @@ module.exports = { tryAndWait, mySecret, promisifyGunNode: require('./promisifygun'), - didDisconnect + didDisconnect, + asyncForEach }