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
|
|
|
|
constructor (filePathArg: string) {
|
|
|
|
this.workerPath = filePathArg
|
|
|
|
}
|
|
|
|
|
|
|
|
run () {
|
2017-03-04 10:59:56 +00:00
|
|
|
let done = smartq.defer()
|
2017-03-04 10:40:32 +00:00
|
|
|
let forkPath = (() => {
|
|
|
|
if (workerBasePath) {
|
|
|
|
return plugins.path.join(workerBasePath, this.workerPath)
|
|
|
|
} else {
|
|
|
|
return this.workerPath
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
this.threadChildProcess = childProcess.fork(forkPath)
|
2017-03-04 10:59:56 +00:00
|
|
|
done.resolve(this.threadChildProcess)
|
|
|
|
return done.promise
|
2017-03-04 10:40:32 +00:00
|
|
|
}
|
|
|
|
}
|