-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
39 lines (32 loc) · 1.05 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
export type Options = {
/**
The time in milliseconds to wait before timing out.
Keep in mind that execution time can vary between different hardware and Node.js versions. Set a generous timeout to avoid flakiness.
*/
readonly timeout?: number;
};
/**
Returns a wrapped version of the given function that throws a timeout error if the execution takes longer than the given timeout.
@example
```
import functionTimeout, {isTimeoutError} from 'function-timeout';
const generateNumbers = count => {
// Imagine this takes a long time.
};
const generateNumbersWithTimeout = functionTimeout(generateNumbers, {timeout: 100});
try {
console.log(generateNumbersWithTimeout(500));
} catch (error) {
if (isTimeoutError(error)) {
console.error('Timed out');
} else {
throw error;
}
}
```
*/
export default function functionTimeout<T extends Function>(function_: T, options?: Options): T; // eslint-disable-line @typescript-eslint/ban-types
/**
Returns a boolean for whether the given error is a timeout error.
*/
export function isTimeoutError(error: unknown): boolean;