Commit | Line | Data |
---|---|---|
8eac9a09 JB |
1 | import chalk from 'chalk'; |
2 | ||
7874b0b1 | 3 | export class WorkerUtils { |
d5bd1c00 JB |
4 | private constructor() { |
5 | // This is intentional | |
6 | } | |
7 | ||
268a74bb JB |
8 | public static async sleep(milliSeconds: number): Promise<NodeJS.Timeout> { |
9 | return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds)); | |
10 | } | |
11 | ||
7874b0b1 | 12 | public static defaultExitHandler = (code: number): void => { |
6bd808fd JB |
13 | if (code === 0) { |
14 | console.info(chalk.green('Worker exited successfully')); | |
15 | } else if (code === 1) { | |
16 | console.info(chalk.green('Worker terminated successfully')); | |
17 | } else if (code > 1) { | |
18 | console.error(chalk.red(`Worker exited with exit code: ${code.toString()}`)); | |
7874b0b1 JB |
19 | } |
20 | }; | |
0f187001 JB |
21 | |
22 | public static defaultErrorHandler = (error: Error): void => { | |
23 | console.error(chalk.red('Worker errored: ', error)); | |
24 | }; | |
7874b0b1 | 25 | } |