UNPKG

1.76 kBTypeScriptView Raw
1import { Disposable } from '../index';
2
3/** Run a node script in a separate process. */
4export class Task {
5 // NOTE: this is actually the best we can do here with the REST parameter for
6 // this appearing in the middle of the parameter list, which isn't aligned with
7 // the ES6 spec. Maybe when they rewrite it in JavaScript this will change.
8 /** A helper method to easily launch and run a task once. */
9 // tslint:disable-next-line:no-any
10 static once(taskPath: string, ...args: any[]): Task;
11
12 /** Creates a task. You should probably use .once */
13 constructor(taskPath: string);
14
15 // NOTE: this is actually the best we can do here with the REST parameter
16 // for this appearing in the beginning of the parameter list, which isn't
17 // aligned with the ES6 spec.
18 /**
19 * Starts the task.
20 * Throws an error if this task has already been terminated or if sending a
21 * message to the child process fails.
22 */
23 // tslint:disable-next-line:no-any
24 start(...args: any[]): void;
25
26 /**
27 * Send message to the task.
28 * Throws an error if this task has already been terminated or if sending a
29 * message to the child process fails.
30 */
31 // tslint:disable-next-line:no-any
32 send(message: string | number | boolean | object | null | any[]): void;
33
34 /** Call a function when an event is emitted by the child process. */
35 // tslint:disable-next-line:no-any
36 on(eventName: string, callback: (param: any) => void): Disposable;
37
38 /**
39 * Forcefully stop the running task.
40 * No more events are emitted once this method is called.
41 */
42 terminate(): void;
43
44 /** Cancel the running task and emit an event if it was canceled. */
45 cancel(): boolean;
46}