Last active
June 17, 2023 05:39
-
-
Save gagan-bansal/398a7c087de4e9d9360fc7e09fbc8ffe to your computer and use it in GitHub Desktop.
async tryEach example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {tryEach} = require('async'); | |
(async () => { | |
const array = [12, 6 , 30, 55, 5]; | |
const testArr = array.map(v => { | |
return async function test() { | |
console.log('val: ', v); | |
if (v > 20) return Promise.resolve(v); | |
else return Promise.reject(new Error('not found')); | |
} | |
}); | |
const found = await tryEach(testArr); | |
console.log('found: ', found); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {tryEach} = require('async'); | |
(async () => { | |
const array = [12, 6 , 30, 55, 5]; | |
const testArr = array.map(v => { | |
return function test(cb) { | |
console.log('val: ', v); | |
if (v > 20) cb(null, v); | |
else cb(new Error('not found')); | |
} | |
}); | |
const found = await tryEach(testArr); | |
console.log('found: ', found); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment