Permalink
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
April 28, 2020 16:46
February 1, 2022 18:01
Newer
100644
49 lines (38 sloc)
1.35 KB
Ignoring revisions in .git-blame-ignore-revs.
2
/**
4
6
10
13
15
17
*/
20
21
/**
22
Get the first fulfilled promise that satisfies the provided testing function.
23
24
@param input - An iterable of promises/values to test.
25
@param tester - This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.
26
@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`.
27
28
@example
29
```
30
import {pathExists} from 'path-exists';
31
import pLocate from 'p-locate';
32
33
const files = [
34
'unicorn.png',
35
'rainbow.png', // Only this one actually exists on disk
36
'pony.png'
37
];
38
39
const foundPath = await pLocate(files, file => pathExists(file));
40
41
console.log(foundPath);
42
//=> 'rainbow'
43
```
44
*/
45
export default function pLocate<ValueType>(
46
input: Iterable<PromiseLike<ValueType> | ValueType>,
47
tester: (element: ValueType) => PromiseLike<boolean> | boolean,
48
options?: Options
49
): Promise<ValueType | undefined>;