JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 163725022
  • Score
    100M100P100Q247723F
  • License MIT

Get the first fulfilled promise that satisfies the provided testing function

Package Exports

  • p-locate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p-locate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

p-locate Build Status

Get the first fulfilled promise that satisfies the provided testing function

Think of it like an async version of Array#find.

Install

$ npm install --save p-locate

Usage

Here we find the first file that exists on disk, in array order.

const pathExists = require('path-exists');
const pLocate = require('p-locate');

const files = [
    'unicorn.png',
    'rainbow.png',
    getUserSpecifiedPath() //=> Promise
];

pLocate(files, file => pathExists(file), {concurrency: 1});

The above is just an example. Use locate-path if you need this.

API

pLocate(input, tester, [options])

Returns a Promise that is fulfilled when tester resolves to true or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or undefined if tester never resolved to true.

input

Type: Iterable<Promise|any>

Set {concurrency: 1} to preserve the search order.

tester(element)

Type: Function

Expected to return a Promise<boolean> or boolean.

options

Type: Object

concurrency

Type: number
Default: Infinity
Minimum: 1

Number of concurrently pending promises returned by tester.

  • p-map - Map over promises concurrently
  • p-filter - Filter promises concurrently
  • p-any - Wait for any promise to be fulfilled
  • More…

License

MIT © Sindre Sorhus