https://github.com/autonomoussoftware/promise-find
Find the promise call that satisfies the testing function
https://github.com/autonomoussoftware/promise-find
Last synced: about 1 year ago
JSON representation
Find the promise call that satisfies the testing function
- Host: GitHub
- URL: https://github.com/autonomoussoftware/promise-find
- Owner: autonomoussoftware
- License: mit
- Created: 2019-09-19T19:12:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-06T17:46:27.000Z (almost 5 years ago)
- Last Synced: 2025-04-08T10:52:12.435Z (about 1 year ago)
- Language: JavaScript
- Size: 84 KB
- Stars: 2
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-find
[](https://travis-ci.com/autonomoussoftware/promise-find)
[](https://github.com/bloq/eslint-config-bloq)
[](https://snyk.io/test/github/autonomoussoftware/promise-find?targetFile=package.json)
Find the promise call that satisfies the testing function.
## Installation
```shell
npm install promise-find
```
## Usage
```js
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'
})
```
## API
### `promiseFind(list, test)`
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.
#### `list`
An array of functions that receive no arguments and return either a value or a
promis.
#### `test`
The function used to check for a match.
It defaults to the "identity" function so any truthy value will pass.
## License
MIT