add basic functionality

This commit is contained in:
2017-01-29 20:50:36 +01:00
parent 7c7f2f8b90
commit 78b5412630
27 changed files with 210 additions and 160 deletions

View File

@ -1,2 +1,2 @@
export * from './smartipc.classes.ipcmaster'
export * from './smartipc.classes.ipcchild'
export * from './smartipc.classes.thread'
export * from './smartipc.classes.threadfunction'

View File

@ -1,32 +1,34 @@
import 'typings-global'
import * as plugins from './smartipc.plugins'
import * as q from 'smartq'
let threads = require('threads')
export interface IThreadFunction {
(input, done): void
export let setWorkerBasePath = (basePathArg: string) => {
plugins.threads.config.set({
basepath: {
node: basePathArg
}
})
}
export class Thread {
thread
constructor(functionArg: IThreadFunction) {
this.thread = threads.spawn(functionArg)
this.thread.on('error', function() {
})
this.thread.on('exit' function() {
})
this.thread.on('message')
constructor(filePathArg: string) {
this.thread = plugins.threads.spawn(filePathArg)
}
/**
* sends a message to the spawned process
*/
send(message) {
this.thread.send(message)
send<T>(message: any): Promise<T> {
let done = q.defer<T>()
this.thread.send(message).on('message', (message: T) => {
done.resolve(message)
}).on('error', err => {
done.reject(err)
})
return done.promise
}
/**
* sends a message to
*/
kill() {
this.thread.kill()
}
}

View File

@ -0,0 +1,31 @@
import 'typings-global'
import * as plugins from './smartipc.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<T>(message: any): Promise<T> {
let done = q.defer<T>()
this.thread.send(message).on('message', (message: T) => {
done.resolve(message)
}).on('error', err => {
done.reject(err)
})
return done.promise
}
kill() {
this.thread.kill()
}
}

8
ts/smartipc.plugins.ts Normal file
View File

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

0
ts/smartipc.pool.ts Normal file
View File