1 # p-locate [![Build Status](https://travis-ci.org/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.org/sindresorhus/p-locate)
3 > Get the first fulfilled promise that satisfies the provided testing function
5 Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
11 $ npm install --save p-locate
17 Here we find the first file that exists on disk, in array order.
20 const pathExists = require('path-exists');
21 const pLocate = require('p-locate');
25 'rainbow.png', // only this one actually exists on disk
29 pLocate(files, file => pathExists(file)).then(foundPath => {
30 console.log(foundPath);
35 *The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
40 ### pLocate(input, tester, [options])
42 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`.
46 Type: `Iterable<Promise|any>`
52 Expected to return a `Promise<boolean>` or boolean.
61 Default: `Infinity`<br>
64 Number of concurrently pending promises returned by `tester`.
71 Preserve `input` order when searching.
73 Disable this to improve performance if you don't care about the order.
78 - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
79 - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
80 - [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
81 - [More…](https://github.com/sindresorhus/promise-fun)
86 MIT © [Sindre Sorhus](https://sindresorhus.com)