Find the promise call that satisfies the testing function.
npm install promise-find
const promiseFind = require('promise-find')
promiseFind([
() => Promise.resolve(null),
() => Promise.resolve('match'),
() => Promise.reject(new Error('never called')),
() => Promise.resolve('never called either')
]).then(function(result) {
console.log(result) // prints 'match'
})
Returns a Promise
that will resolve to the result of the first function call
that passes the test or null
if no one passes the test.
If any function fails, the promise will be a rejected the error.
An array of functions that receive no arguments and return either a value or a promis.
The function used to check for a match. It defaults to the "identity" function so any truthy value will pass.
MIT