Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevva/p-one
Test whether some promise passes a testing function
https://github.com/kevva/p-one
async async-await async-functions await concurrency iteration nodejs parallel promise test
Last synced: 3 months ago
JSON representation
Test whether some promise passes a testing function
- Host: GitHub
- URL: https://github.com/kevva/p-one
- Owner: kevva
- License: mit
- Created: 2017-05-24T01:58:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-15T09:23:30.000Z (almost 6 years ago)
- Last Synced: 2024-10-12T01:06:40.160Z (4 months ago)
- Topics: async, async-await, async-functions, await, concurrency, iteration, nodejs, parallel, promise, test
- Language: JavaScript
- Size: 6.84 KB
- Stars: 14
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# p-one [![Build Status](https://travis-ci.org/kevva/p-one.svg?branch=master)](https://travis-ci.org/kevva/p-one)
> Test whether some promise passes a testing function
Like [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) for promises.
## Install
```
$ npm install --save p-one
```## Usage
```js
const pOne = require('p-one');
const getContinent = require('get-continent'); // not a real moduleconst places = [
getCapital('Norway').then(info => info.name),
'Bangkok, Thailand',
'Berlin, Germany',
'Tokyo, Japan'
];const testFunction = async place => {
const continent = await getContinent(place);
return continent === 'europe';
}(async () => {
const result = await pOne(places, testFunction)
console.log(result);
//=> true
})();
```## API
### pOne(input, testFunction, [options])
Returns a `Promise` that is fulfilled when any promise in `input` and ones returned from `testFunction` are fulfilled, or rejects if any of the promises reject. The fulfilled value is a `boolean` that is `true` if any promise passed the test and `false` otherwise.
#### input
Type: `Iterable`
Iterated over concurrently in the `testFunction` function.
#### testFunction(element, index)
Type: `Function`
Expected to return a `Promise` or `boolean`.
#### options
Type: `Object`
##### concurrency
Type: `number`
Default: `Infinity`
Minimum: `1`Number of concurrently pending promises returned by `testFunction`.
## Related
* [p-every](https://github.com/kevva/p-every) - Test whether all promises passes a testing function
* [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
* [p-locate](https://github.com/sindresorhus/p-locate) - Get the first fulfilled promise that satisfies the provided testing function
* [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
* [More…](https://github.com/sindresorhus/promise-fun)## License
MIT © [Kevin Martensson](http://github.com/kevva)