main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | declare namespace pLocate {
|
---|
2 | interface Options {
|
---|
3 | /**
|
---|
4 | Number of concurrently pending promises returned by `tester`. Minimum: `1`.
|
---|
5 |
|
---|
6 | @default Infinity
|
---|
7 | */
|
---|
8 | readonly concurrency?: number;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | Preserve `input` order when searching.
|
---|
12 |
|
---|
13 | Disable this to improve performance if you don't care about the order.
|
---|
14 |
|
---|
15 | @default true
|
---|
16 | */
|
---|
17 | readonly preserveOrder?: boolean;
|
---|
18 | }
|
---|
19 | }
|
---|
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 = require('path-exists');
|
---|
31 | import pLocate = require('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 | (async () => {
|
---|
40 | const foundPath = await pLocate(files, file => pathExists(file));
|
---|
41 |
|
---|
42 | console.log(foundPath);
|
---|
43 | //=> 'rainbow'
|
---|
44 | })();
|
---|
45 | ```
|
---|
46 | */
|
---|
47 | declare function pLocate<ValueType>(
|
---|
48 | input: Iterable<PromiseLike<ValueType> | ValueType>,
|
---|
49 | tester: (element: ValueType) => PromiseLike<boolean> | boolean,
|
---|
50 | options?: pLocate.Options
|
---|
51 | ): Promise<ValueType | undefined>;
|
---|
52 |
|
---|
53 | export = pLocate;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.