Comparing version 1.1.0 to 2.0.0
17
index.js
'use strict'; | ||
const pSome = require('p-some'); | ||
const PCancelable = require('p-cancelable'); | ||
module.exports = (iterable, opts) => pSome(iterable, Object.assign({}, opts, {count: 1})).then(values => values[0]); | ||
const pAny = (iterable, options) => { | ||
const anyCancelable = pSome(iterable, {...options, count: 1}); | ||
return PCancelable.fn(async onCancel => { | ||
onCancel(() => { | ||
anyCancelable.cancel(); | ||
}); | ||
const [value] = await anyCancelable; | ||
return value; | ||
})(); | ||
}; | ||
module.exports = pAny; | ||
module.exports.default = pAny; | ||
module.exports.AggregateError = pSome.AggregateError; |
{ | ||
"name": "p-any", | ||
"version": "1.1.0", | ||
"description": "Wait for any promise to be fulfilled", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-any", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"any", | ||
"resolved", | ||
"wait", | ||
"collection", | ||
"iterable", | ||
"iterator", | ||
"race", | ||
"fulfilled", | ||
"fastest", | ||
"one", | ||
"single", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"dependencies": { | ||
"p-some": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"delay": "^2.0.0", | ||
"xo": "*" | ||
} | ||
"name": "p-any", | ||
"version": "2.0.0", | ||
"description": "Wait for any promise to be fulfilled", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-any", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"any", | ||
"resolved", | ||
"wait", | ||
"collection", | ||
"iterable", | ||
"iterator", | ||
"race", | ||
"fulfilled", | ||
"fastest", | ||
"one", | ||
"single", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"dependencies": { | ||
"p-cancelable": "^1.1.0", | ||
"p-some": "^4.0.0", | ||
"type-fest": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"delay": "^4.1.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -25,10 +25,12 @@ # p-any [![Build Status](https://travis-ci.org/sindresorhus/p-any.svg?branch=master)](https://travis-ci.org/sindresorhus/p-any) | ||
pAny([ | ||
got.head('github.com').then(() => 'github'), | ||
got.head('google.com').then(() => 'google'), | ||
got.head('twitter.com').then(() => 'twitter'), | ||
]).then(first => { | ||
(async () => { | ||
const first = await pAny([ | ||
got.head('https://github.com').then(() => 'github'), | ||
got.head('https://google.com').then(() => 'google'), | ||
got.head('https://twitter.com').then(() => 'twitter'), | ||
]); | ||
console.log(first); | ||
//=> 'google' | ||
}); | ||
})(); | ||
``` | ||
@@ -41,3 +43,3 @@ | ||
Returns a `Promise` that is fulfilled when any promise from `input` is fulfilled. If all the `input` promises reject, it will reject with an [`AggregateError`](https://github.com/sindresorhus/aggregate-error) error. | ||
Returns a [cancelable `Promise`](https://github.com/sindresorhus/p-cancelable) that is fulfilled when any promise from `input` is fulfilled. If all the `input` promises reject, it will reject with an [`AggregateError`](https://github.com/sindresorhus/aggregate-error) error. | ||
@@ -44,0 +46,0 @@ #### input |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5011
5
32
73
0
3
4
+ Addedp-cancelable@^1.1.0
+ Addedtype-fest@^0.1.0
+ Addedaggregate-error@3.1.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedp-cancelable@1.1.02.1.1(transitive)
+ Addedp-some@4.1.0(transitive)
+ Addedtype-fest@0.1.0(transitive)
- Removedaggregate-error@1.0.0(transitive)
- Removedclean-stack@1.3.0(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedp-some@2.0.1(transitive)
Updatedp-some@^4.0.0