import 'typings-global'; import * as plugins from './smartspawn.plugins'; import * as q from 'smartq'; export interface IThreadFunction { (input, done): void; } export class ThreadFunction { thread; constructor(functionArg: IThreadFunction) { this.thread = plugins.threads.spawn(functionArg); } /** * 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(); } }