MCPcopy
hub / github.com/codeceptjs/CodeceptJS / forEachAsync

Function forEachAsync

lib/helper/WebDriver.js:2998–3012  ·  view source on GitHub ↗

* 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 })

Source from the content-addressed store, hash-verified

2996 * @return {Promise<Array>} - Array of values.
2997 */
2998async 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.

Callers 15

_withinBeginMethod · 0.85
grabTextFromAllMethod · 0.85
grabHTMLFromAllMethod · 0.85
grabValueFromAllMethod · 0.85
grabAttributeFromAllMethod · 0.85
seeElementMethod · 0.85
dontSeeElementMethod · 0.85
closeOtherTabsMethod · 0.85
waitForEnabledMethod · 0.85

Calls 2

callbackFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected