2017-03-04 10:40:32 +00:00
|
|
|
import * as plugins from './smartipc.plugins'
|
2017-03-04 10:59:56 +00:00
|
|
|
import * as smartq from 'smartq'
|
2017-03-04 10:40:32 +00:00
|
|
|
import * as childProcess from 'child_process'
|
|
|
|
|
|
|
|
import { workerBasePath } from './smartipc.classes.thread'
|
|
|
|
|
|
|
|
export class ThreadSimple {
|
|
|
|
workerPath: string
|
|
|
|
threadChildProcess: childProcess.ChildProcess
|
2017-03-04 11:24:32 +00:00
|
|
|
forkOptions: childProcess.ForkOptions
|
|
|
|
constructor (filePathArg: string, forkOptionsArg: childProcess.ForkOptions = {}) {
|
2017-03-04 10:40:32 +00:00
|
|
|
this.workerPath = filePathArg
|
2017-03-04 11:24:32 +00:00
|
|
|
this.forkOptions = forkOptionsArg
|
2017-03-04 10:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run () {
|
2017-03-04 11:05:53 +00:00
|
|
|
let done = smartq.defer<childProcess.ChildProcess>()
|
2017-03-04 10:40:32 +00:00
|
|
|
let forkPath = (() => {
|
|
|
|
if (workerBasePath) {
|
|
|
|
return plugins.path.join(workerBasePath, this.workerPath)
|
|
|
|
} else {
|
|
|
|
return this.workerPath
|
|
|
|
}
|
|
|
|
})()
|
2017-03-04 11:24:32 +00:00
|
|
|
this.threadChildProcess = childProcess.fork(forkPath, [], this.forkOptions)
|
2017-03-04 10:59:56 +00:00
|
|
|
done.resolve(this.threadChildProcess)
|
|
|
|
return done.promise
|
2017-03-04 10:40:32 +00:00
|
|
|
}
|
|
|
|
}
|