* Mimic Array.forEach() API, but with an async callback function. * Execute each callback on each array item serially. Useful when using WebDriver API. * * Added due because of problem with chrome driver when too many requests * are made simultaneously. https://bugs.chromium.org/p/chromedriver/i
(array, callback, options = { expandArrayResults: true })
| 2996 | * @return {Promise<Array>} - Array of values. |
| 2997 | */ |
| 2998 | async function forEachAsync(array, callback, options = { expandArrayResults: true }) { |
| 2999 | const { expandArrayResults = true } = options |
| 3000 | const inputArray = Array.isArray(array) ? array : [array] |
| 3001 | const values = [] |
| 3002 | for (let index = 0; index < inputArray.length; index++) { |
| 3003 | const res = await callback(inputArray[index], index, inputArray) |
| 3004 | |
| 3005 | if (Array.isArray(res) && expandArrayResults) { |
| 3006 | res.forEach(val => values.push(val)) |
| 3007 | } else if (res) { |
| 3008 | values.push(res) |
| 3009 | } |
| 3010 | } |
| 3011 | return values |
| 3012 | } |
| 3013 | |
| 3014 | /** |
| 3015 | * Mimic Array.filter() API, but with an async callback function. |
no test coverage detected