smartspawn/ts/smartspawn.classes.threadsimple.ts

30 lines
843 B
TypeScript
Raw Normal View History

2022-07-28 20:35:16 +00:00
import * as plugins from './smartspawn.plugins.js';
2019-04-08 13:39:17 +00:00
import * as smartpromise from '@pushrocks/smartpromise';
2018-08-02 13:31:05 +00:00
import * as childProcess from 'child_process';
export class ThreadSimple {
2019-08-22 07:26:30 +00:00
public workerPath: string;
public threadChildProcess: childProcess.ChildProcess;
public forkOptions: childProcess.ForkOptions;
public argvArgs: string[];
2018-08-02 13:31:05 +00:00
constructor(
filePathArg: string,
argvArgs: string[] = [],
forkOptionsArg: childProcess.ForkOptions = {}
) {
this.workerPath = filePathArg;
this.forkOptions = forkOptionsArg;
this.argvArgs = argvArgs;
}
2019-08-22 07:26:30 +00:00
public async start() {
const forkPath = this.workerPath;
2018-08-02 13:31:05 +00:00
this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions);
2019-08-22 07:26:30 +00:00
return this.threadChildProcess;
}
public async stop() {
this.threadChildProcess.kill();
2018-08-02 13:31:05 +00:00
}
}