import * as plugins from './smartipc.plugins' import * as q from 'smartq' export let setWorkerBasePath = (basePathArg: string) => { plugins.threads.config.set({ basepath: { node: basePathArg } }) } export class Thread { thread constructor(filePathArg: string) { this.thread = plugins.threads.spawn(filePathArg) } /** * sends a message to the spawned process */ send(message: any): Promise { let done = q.defer() this.thread.send(message).on('message', (message: T) => { done.resolve(message) }).on('error', err => { done.reject(err) }) return done.promise } kill() { this.thread.kill() } }