You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
515 B
23 lines
515 B
'use strict';
|
|
const pSome = require('p-some');
|
|
const PCancelable = require('p-cancelable');
|
|
|
|
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;
|
|
// TODO: Remove this for the next major release
|
|
module.exports.default = pAny;
|
|
|
|
module.exports.AggregateError = pSome.AggregateError;
|