.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / p-locate / readme.md
1 # p-locate [![Build Status](https://travis-ci.org/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.org/sindresorhus/p-locate)
2
3 > Get the first fulfilled promise that satisfies the provided testing function
4
5 Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
6
7
8 ## Install
9
10 ```
11 $ npm install --save p-locate
12 ```
13
14
15 ## Usage
16
17 Here we find the first file that exists on disk, in array order.
18
19 ```js
20 const pathExists = require('path-exists');
21 const pLocate = require('p-locate');
22
23 const files = [
24         'unicorn.png',
25         'rainbow.png', // only this one actually exists on disk
26         'pony.png'
27 ];
28
29 pLocate(files, file => pathExists(file)).then(foundPath => {
30         console.log(foundPath);
31         //=> 'rainbow'
32 });
33 ```
34
35 *The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
36
37
38 ## API
39
40 ### pLocate(input, tester, [options])
41
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`.
43
44 #### input
45
46 Type: `Iterable<Promise|any>`
47
48 #### tester(element)
49
50 Type: `Function`
51
52 Expected to return a `Promise<boolean>` or boolean.
53
54 #### options
55
56 Type: `Object`
57
58 ##### concurrency
59
60 Type: `number`<br>
61 Default: `Infinity`<br>
62 Minimum: `1`
63
64 Number of concurrently pending promises returned by `tester`.
65
66 ##### preserveOrder
67
68 Type: `boolean`<br>
69 Default: `true`
70
71 Preserve `input` order when searching.
72
73 Disable this to improve performance if you don't care about the order.
74
75
76 ## Related
77
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)
82
83
84 ## License
85
86 MIT © [Sindre Sorhus](https://sindresorhus.com)