add basic functionality
This commit is contained in:
@ -1,2 +1,2 @@
|
||||
export * from './smartipc.classes.ipcmaster'
|
||||
export * from './smartipc.classes.ipcchild'
|
||||
export * from './smartipc.classes.thread'
|
||||
export * from './smartipc.classes.threadfunction'
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
31
ts/smartipc.classes.threadfunction.ts
Normal file
31
ts/smartipc.classes.threadfunction.ts
Normal 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
8
ts/smartipc.plugins.ts
Normal 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
0
ts/smartipc.pool.ts
Normal file
Reference in New Issue
Block a user