-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.d.ts
42 lines (34 loc) · 1.08 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export type PromiseWithTime<ValueType> = {
/**
The elapsed time in milliseconds.
*/
readonly time?: number;
} & Promise<ValueType>;
declare const pTime: {
/**
Measure the time a promise takes to resolve.
@param asyncFunction - Promise-returning/async function.
@returns A decorated version of `asyncFunction`.
@example
```
import pTime from 'p-time';
import {execa} from 'execa';
const promise = pTime(execa)('sleep', ['1']);
await promise;
console.log(promise.time);
//=> 1016
```
*/
<ArgumentsType extends unknown[], ReturnType>(
asyncFunction: (...arguments: ArgumentsType) => PromiseLike<ReturnType>
): (...arguments: ArgumentsType) => PromiseWithTime<ReturnType>;
/**
Measure the time a promise takes to resolve. Logs the elapsed time.
@param asyncFunction - Promise-returning/async function.
@returns A decorated version of `asyncFunction`.
*/
log<ArgumentsType extends unknown[], ReturnType>(
asyncFunction: (...arguments: ArgumentsType) => PromiseLike<ReturnType>
): (...arguments: ArgumentsType) => PromiseWithTime<ReturnType>;
};
export default pTime;