add threadsimple for simple forking
This commit is contained in:
@ -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'
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
25
ts/smartipc.classes.threadsimple.ts
Normal file
25
ts/smartipc.classes.threadsimple.ts
Normal 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
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user