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 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
30 const foundPath = await pLocate(files, file => pathExists(file));
32 console.log(foundPath);
37 *The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
42 ### pLocate(input, tester, [options])
44 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`.
48 Type: `Iterable<Promise|any>`
54 Expected to return a `Promise<boolean>` or boolean.
63 Default: `Infinity`<br>
66 Number of concurrently pending promises returned by `tester`.
73 Preserve `input` order when searching.
75 Disable this to improve performance if you don't care about the order.
80 - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
81 - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
82 - [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
83 - [More…](https://github.com/sindresorhus/promise-fun)
88 MIT © [Sindre Sorhus](https://sindresorhus.com)