smartspawn/ts/smartspawn.classes.threadsimple.ts
2024-05-14 19:28:39 +02:00

30 lines
844 B
TypeScript

import * as plugins from './smartspawn.plugins.js';
import * as smartpromise from '@push.rocks/smartpromise';
import * as childProcess from 'child_process';
export class ThreadSimple {
public workerPath: string;
public threadChildProcess: childProcess.ChildProcess;
public forkOptions: childProcess.ForkOptions;
public argvArgs: string[];
constructor(
filePathArg: string,
argvArgs: string[] = [],
forkOptionsArg: childProcess.ForkOptions = {}
) {
this.workerPath = filePathArg;
this.forkOptions = forkOptionsArg;
this.argvArgs = argvArgs;
}
public async start() {
const forkPath = this.workerPath;
this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions);
return this.threadChildProcess;
}
public async stop() {
this.threadChildProcess.kill();
}
}