add threadsimple for simple forking

This commit is contained in:
2017-03-04 11:40:32 +01:00
parent 661e782367
commit 347036cf4e
16 changed files with 88 additions and 17 deletions

View File

@ -1,4 +1,6 @@
export * from './smartipc.classes.thread'
export * from './smartipc.classes.threadfunction'
export * from './smartipc.classes.threadsimple'
export * from './smartipc.classes.pool'
export * from './smartipc.wrap'

View File

@ -1,11 +1,11 @@
import * as plugins from './smartipc.plugins'
export class Pool {
pool
constructor() {
this.pool = new plugins.threads.Pool()
}
run(workerPathArg: string) {
return this.pool.run(workerPathArg)
}
pool
constructor() {
this.pool = new plugins.threads.Pool()
}
run(workerPathArg: string) {
return this.pool.run(workerPathArg)
}
}

View File

@ -3,10 +3,13 @@ import * as q from 'smartq'
import { Pool } from './smartipc.classes.pool'
export let workerBasePath: string = null
export let setWorkerBasePath = (basePathArg: string) => {
workerBasePath = basePathArg
plugins.threads.config.set({
basepath: {
node: basePathArg
node: workerBasePath
}
})
}

View File

@ -0,0 +1,25 @@
import * as plugins from './smartipc.plugins'
import * as q from 'smartq'
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 () {
let forkPath = (() => {
if (workerBasePath) {
return plugins.path.join(workerBasePath, this.workerPath)
} else {
return this.workerPath
}
})()
this.threadChildProcess = childProcess.fork(forkPath)
return this.threadChildProcess
}
}

View File

@ -1,8 +1,10 @@
import 'typings-global'
import * as path from 'path'
let threads = require('threads')
import * as smartq from 'smartq'
export {
path,
smartq,
threads
}