1 |
3a515b92
|
cagy
|
declare const pTry: {
|
2 |
|
|
/**
|
3 |
|
|
Start a promise chain.
|
4 |
|
|
|
5 |
|
|
@param fn - The function to run to start the promise chain.
|
6 |
|
|
@param arguments - Arguments to pass to `fn`.
|
7 |
|
|
@returns The value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
|
8 |
|
|
|
9 |
|
|
@example
|
10 |
|
|
```
|
11 |
|
|
import pTry = require('p-try');
|
12 |
|
|
|
13 |
|
|
(async () => {
|
14 |
|
|
try {
|
15 |
|
|
const value = await pTry(() => {
|
16 |
|
|
return synchronousFunctionThatMightThrow();
|
17 |
|
|
});
|
18 |
|
|
console.log(value);
|
19 |
|
|
} catch (error) {
|
20 |
|
|
console.error(error);
|
21 |
|
|
}
|
22 |
|
|
})();
|
23 |
|
|
```
|
24 |
|
|
*/
|
25 |
|
|
<ValueType, ArgumentsType extends unknown[]>(
|
26 |
|
|
fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
|
27 |
|
|
...arguments: ArgumentsType
|
28 |
|
|
): Promise<ValueType>;
|
29 |
|
|
|
30 |
|
|
// TODO: remove this in the next major version, refactor the whole definition to:
|
31 |
|
|
// declare function pTry<ValueType, ArgumentsType extends unknown[]>(
|
32 |
|
|
// fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
|
33 |
|
|
// ...arguments: ArgumentsType
|
34 |
|
|
// ): Promise<ValueType>;
|
35 |
|
|
// export = pTry;
|
36 |
|
|
default: typeof pTry;
|
37 |
|
|
};
|
38 |
|
|
|
39 |
|
|
export = pTry;
|