diff --git a/dist/index.d.ts b/dist/index.d.ts index 960a27d..8e25055 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,2 +1,2 @@ -export * from './smartipc.classes.ipcmaster'; -export * from './smartipc.classes.ipcchild'; +export * from './smartipc.classes.thread'; +export * from './smartipc.classes.threadfunction'; diff --git a/dist/index.js b/dist/index.js index 7ed71fe..a152734 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,6 +2,6 @@ function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } -__export(require("./smartipc.classes.ipcmaster")); -__export(require("./smartipc.classes.ipcchild")); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsa0RBQTRDO0FBQzVDLGlEQUEyQyJ9 \ No newline at end of file +__export(require("./smartipc.classes.thread")); +__export(require("./smartipc.classes.threadfunction")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsK0NBQXlDO0FBQ3pDLHVEQUFpRCJ9 \ No newline at end of file diff --git a/dist/smartipc.classes.ipcchild.d.ts b/dist/smartipc.classes.ipcchild.d.ts deleted file mode 100644 index 3a774ac..0000000 --- a/dist/smartipc.classes.ipcchild.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IpcTarget } from './smartipc.classes.ipctarget'; -export interface IpcChildConstructorOptions { -} -/** - * class Ipcclient represents the child process - */ -export declare class IpcChild extends IpcTarget { - constructor(optionsArg: IpcChildConstructorOptions); - call(ipctarget: any, targetFunction: any, dataArg: any): void; -} diff --git a/dist/smartipc.classes.ipcchild.js b/dist/smartipc.classes.ipcchild.js deleted file mode 100644 index 892347b..0000000 --- a/dist/smartipc.classes.ipcchild.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -const smartipc_classes_ipctarget_1 = require("./smartipc.classes.ipctarget"); -let defaultOptions = {}; -/** - * class Ipcclient represents the child process - */ -class IpcChild extends smartipc_classes_ipctarget_1.IpcTarget { - constructor(optionsArg) { - super({ alias: 'child' }); - } - call(ipctarget, targetFunction, dataArg) { - } -} -exports.IpcChild = IpcChild; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGNjaGlsZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMuaXBjY2hpbGQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUNBLDZFQUF3RDtBQU14RCxJQUFJLGNBQWMsR0FBK0IsRUFFaEQsQ0FBQTtBQUVEOztHQUVHO0FBQ0gsY0FBc0IsU0FBUSxzQ0FBUztJQUNuQyxZQUFZLFVBQXNDO1FBQzlDLEtBQUssQ0FBQyxFQUFDLEtBQUssRUFBRSxPQUFPLEVBQUMsQ0FBQyxDQUFBO0lBQzNCLENBQUM7SUFDRCxJQUFJLENBQUMsU0FBUyxFQUFDLGNBQWMsRUFBQyxPQUFPO0lBRXJDLENBQUM7Q0FDSjtBQVBELDRCQU9DIn0= \ No newline at end of file diff --git a/dist/smartipc.classes.ipcmaster.d.ts b/dist/smartipc.classes.ipcmaster.d.ts deleted file mode 100644 index 7680fdd..0000000 --- a/dist/smartipc.classes.ipcmaster.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as plugins from './smartipc.plugins'; -import { IpcTarget } from './smartipc.classes.ipctarget'; -export interface IIpcServeOptions { -} -export interface IIpcChildProcess { - alias: string; - filePath: string; - childProcess: plugins.childProcess.ChildProcess; -} -/** - * class Ipcserve is represents the master process for any chil processes - */ -export declare class IpcMaster extends IpcTarget { - ipcOptions: IIpcServeOptions; - childProcessArray: IIpcChildProcess[]; - constructor(ipcOptionsArg: IIpcServeOptions); - /** - * spawns a child process - */ - spawnProcess(filePath: string, alias: string): void; -} diff --git a/dist/smartipc.classes.ipcmaster.js b/dist/smartipc.classes.ipcmaster.js deleted file mode 100644 index d5461ca..0000000 --- a/dist/smartipc.classes.ipcmaster.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -const plugins = require("./smartipc.plugins"); -const smartipc_classes_ipctarget_1 = require("./smartipc.classes.ipctarget"); -let defaultOptions = {}; -/** - * class Ipcserve is represents the master process for any chil processes - */ -class IpcMaster extends smartipc_classes_ipctarget_1.IpcTarget { - constructor(ipcOptionsArg) { - super({ alias: 'master' }); - this.ipcOptions = plugins.lodash.merge({}, defaultOptions, ipcOptionsArg); - } - /** - * spawns a child process - */ - spawnProcess(filePath, alias) { - let childProcess = plugins.childProcess.fork('ls', ['-lh', '/usr']); - childProcess.stdout.on('data', (data) => { - console.log(`stdout: ${data}`); - }); - childProcess.stderr.on('data', (data) => { - console.log(`stderr: ${data}`); - }); - childProcess.on('close', (code) => { - console.log(`child process exited with code ${code}`); - }); - } -} -exports.IpcMaster = IpcMaster; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGNtYXN0ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLmlwY21hc3Rlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDZFQUF3RDtBQU14RCxJQUFJLGNBQWMsR0FBcUIsRUFFdEMsQ0FBQTtBQVFEOztHQUVHO0FBQ0gsZUFBdUIsU0FBUSxzQ0FBUztJQUdwQyxZQUFZLGFBQStCO1FBQ3ZDLEtBQUssQ0FBQyxFQUFDLEtBQUssRUFBRSxRQUFRLEVBQUMsQ0FBQyxDQUFBO1FBQ3hCLElBQUksQ0FBQyxVQUFVLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxFQUFDLGNBQWMsRUFBQyxhQUFhLENBQUMsQ0FBQTtJQUMzRSxDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUMsUUFBZ0IsRUFBRSxLQUFhO1FBRXhDLElBQUksWUFBWSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLElBQUksRUFBRSxDQUFDLEtBQUssRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFBO1FBRW5FLFlBQVksQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxDQUFDLElBQUk7WUFDcEMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLElBQUksRUFBRSxDQUFDLENBQUE7UUFDOUIsQ0FBQyxDQUFDLENBQUE7UUFFRixZQUFZLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxJQUFJO1lBQ3BDLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxJQUFJLEVBQUUsQ0FBQyxDQUFBO1FBQzlCLENBQUMsQ0FBQyxDQUFBO1FBRUYsWUFBWSxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxJQUFJO1lBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLElBQUksRUFBRSxDQUFDLENBQUE7UUFDckQsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBQ0o7QUEzQkQsOEJBMkJDIn0= \ No newline at end of file diff --git a/dist/smartipc.classes.ipctarget.d.ts b/dist/smartipc.classes.ipctarget.d.ts deleted file mode 100644 index 7813bab..0000000 --- a/dist/smartipc.classes.ipctarget.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface ITargetConstructorOptions { - alias: string; -} -/** - * - */ -export declare class IpcTarget { - alias: string; - private funcArray; - constructor(optionsArg: ITargetConstructorOptions); - /** - * registers a function - */ - register(funcArrayArg: any[]): void; -} diff --git a/dist/smartipc.classes.ipctarget.js b/dist/smartipc.classes.ipctarget.js deleted file mode 100644 index b4e931b..0000000 --- a/dist/smartipc.classes.ipctarget.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -/** - * - */ -class IpcTarget { - constructor(optionsArg) { - this.alias = optionsArg.alias; - } - /** - * registers a function - */ - register(funcArrayArg) { - for (let funcItem of funcArrayArg) { - this.funcArray.push(funcItem); - } - } -} -exports.IpcTarget = IpcTarget; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGN0YXJnZXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLmlwY3RhcmdldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBTUE7O0dBRUc7QUFDSDtJQUlJLFlBQVksVUFBcUM7UUFDN0MsSUFBSSxDQUFDLEtBQUssR0FBRyxVQUFVLENBQUMsS0FBSyxDQUFBO0lBQ2pDLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxZQUFtQjtRQUN4QixHQUFHLENBQUMsQ0FBQyxJQUFJLFFBQVEsSUFBSSxZQUFZLENBQUMsQ0FBQSxDQUFDO1lBQy9CLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQ2pDLENBQUM7SUFDTCxDQUFDO0NBRUo7QUFqQkQsOEJBaUJDIn0= \ No newline at end of file diff --git a/dist/smartipc.classes.thread.d.ts b/dist/smartipc.classes.thread.d.ts new file mode 100644 index 0000000..c8c544b --- /dev/null +++ b/dist/smartipc.classes.thread.d.ts @@ -0,0 +1,10 @@ +export declare let setWorkerBasePath: (basePathArg: string) => void; +export declare class Thread { + thread: any; + constructor(filePathArg: string); + /** + * sends a message to the spawned process + */ + send(message: any): Promise; + kill(): void; +} diff --git a/dist/smartipc.classes.thread.js b/dist/smartipc.classes.thread.js new file mode 100644 index 0000000..6a047bc --- /dev/null +++ b/dist/smartipc.classes.thread.js @@ -0,0 +1,32 @@ +"use strict"; +const plugins = require("./smartipc.plugins"); +const q = require("smartq"); +exports.setWorkerBasePath = (basePathArg) => { + plugins.threads.config.set({ + basepath: { + node: basePathArg + } + }); +}; +class Thread { + constructor(filePathArg) { + this.thread = plugins.threads.spawn(filePathArg); + } + /** + * sends a message to the spawned process + */ + send(message) { + let done = q.defer(); + this.thread.send(message).on('message', (message) => { + done.resolve(message); + }).on('error', err => { + done.reject(err); + }); + return done.promise; + } + kill() { + this.thread.kill(); + } +} +exports.Thread = Thread; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLnRocmVhZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDRCQUEyQjtBQUVoQixRQUFBLGlCQUFpQixHQUFHLENBQUMsV0FBbUI7SUFDL0MsT0FBTyxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDO1FBQ3ZCLFFBQVEsRUFBRTtZQUNOLElBQUksRUFBRSxXQUFXO1NBQ3BCO0tBQ0osQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFBO0FBRUQ7SUFFSSxZQUFZLFdBQW1CO1FBQzNCLElBQUksQ0FBQyxNQUFNLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDcEQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSSxDQUFJLE9BQVk7UUFDaEIsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBSyxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxTQUFTLEVBQUUsQ0FBQyxPQUFVO1lBQy9DLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDekIsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLE9BQU8sRUFBRSxHQUFHO1lBQ2QsSUFBSSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUNwQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRCxJQUFJO1FBQ0EsSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLEVBQUUsQ0FBQTtJQUN0QixDQUFDO0NBQ0o7QUF0QkQsd0JBc0JDIn0= \ No newline at end of file diff --git a/dist/smartipc.classes.threadfunction.d.ts b/dist/smartipc.classes.threadfunction.d.ts new file mode 100644 index 0000000..5cf68ad --- /dev/null +++ b/dist/smartipc.classes.threadfunction.d.ts @@ -0,0 +1,13 @@ +import 'typings-global'; +export interface IThreadFunction { + (input: any, done: any): void; +} +export declare class ThreadFunction { + thread: any; + constructor(functionArg: IThreadFunction); + /** + * sends a message to the spawned process + */ + send(message: any): Promise; + kill(): void; +} diff --git a/dist/smartipc.classes.threadfunction.js b/dist/smartipc.classes.threadfunction.js new file mode 100644 index 0000000..112034d --- /dev/null +++ b/dist/smartipc.classes.threadfunction.js @@ -0,0 +1,26 @@ +"use strict"; +require("typings-global"); +const plugins = require("./smartipc.plugins"); +const q = require("smartq"); +class ThreadFunction { + constructor(functionArg) { + this.thread = plugins.threads.spawn(functionArg); + } + /** + * sends a message to the spawned process + */ + send(message) { + let done = q.defer(); + this.thread.send(message).on('message', (message) => { + done.resolve(message); + }).on('error', err => { + done.reject(err); + }); + return done.promise; + } + kill() { + this.thread.kill(); + } +} +exports.ThreadFunction = ThreadFunction; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMudGhyZWFkZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qiw4Q0FBNkM7QUFDN0MsNEJBQTJCO0FBTTNCO0lBRUksWUFBWSxXQUE0QjtRQUNwQyxJQUFJLENBQUMsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQ3BELENBQUM7SUFFRDs7T0FFRztJQUNILElBQUksQ0FBSSxPQUFZO1FBQ2hCLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUssQ0FBQTtRQUN2QixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxFQUFFLENBQUMsU0FBUyxFQUFFLENBQUMsT0FBVTtZQUMvQyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsR0FBRztZQUNkLElBQUksQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUE7UUFDcEIsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQsSUFBSTtRQUNBLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxFQUFFLENBQUE7SUFDdEIsQ0FBQztDQUNKO0FBdEJELHdDQXNCQyJ9 \ No newline at end of file diff --git a/dist/smartipc.plugins.d.ts b/dist/smartipc.plugins.d.ts index facd749..302d5e3 100644 --- a/dist/smartipc.plugins.d.ts +++ b/dist/smartipc.plugins.d.ts @@ -1,4 +1,4 @@ import 'typings-global'; -export import beautylog = require('beautylog'); -export import lodash = require('lodash'); -export import childProcess = require('child_process'); +declare let threads: any; +import * as smartq from 'smartq'; +export { smartq, threads }; diff --git a/dist/smartipc.plugins.js b/dist/smartipc.plugins.js index 5615699..7179748 100644 --- a/dist/smartipc.plugins.js +++ b/dist/smartipc.plugins.js @@ -1,6 +1,7 @@ "use strict"; require("typings-global"); -exports.beautylog = require("beautylog"); -exports.lodash = require("lodash"); -exports.childProcess = require("child_process"); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBOEM7QUFDOUMsbUNBQXdDO0FBQ3hDLGdEQUFxRCJ9 \ No newline at end of file +let threads = require('threads'); +exports.threads = threads; +const smartq = require("smartq"); +exports.smartq = smartq; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFLNUIsMEJBQU87QUFKWCxpQ0FBZ0M7QUFHNUIsd0JBQU0ifQ== \ No newline at end of file diff --git a/dist/smartipc.pool.d.ts b/dist/smartipc.pool.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/dist/smartipc.pool.js b/dist/smartipc.pool.js new file mode 100644 index 0000000..8d2cf53 --- /dev/null +++ b/dist/smartipc.pool.js @@ -0,0 +1 @@ +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucG9vbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBvb2wudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9 \ No newline at end of file diff --git a/package.json b/package.json index 4c3db45..d10adf6 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@types/lodash": "^4.14.50", "beautylog": "^6.0.0", "lodash": "^4.17.4", + "smartq": "^1.1.0", "threads": "^0.7.2", "typings-global": "^1.0.14" }, diff --git a/test/child.d.ts b/test/child.d.ts index e69de29..2352369 100644 --- a/test/child.d.ts +++ b/test/child.d.ts @@ -0,0 +1,2 @@ +import 'typings-global'; +import 'smartq'; diff --git a/test/child.js b/test/child.js index 9bffa23..15e3fe5 100644 --- a/test/child.js +++ b/test/child.js @@ -1,4 +1,7 @@ "use strict"; -const smartipc = require("../dist/index"); -let localChild = new smartipc.IpcChild({}); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMENBQXlDO0FBRXpDLElBQUksVUFBVSxHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQSJ9 \ No newline at end of file +require("typings-global"); +require("smartq"); +module.exports = (input, done) => { + done('hi'); +}; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLGtCQUFlO0FBQ2YsTUFBTSxDQUFDLE9BQU8sR0FBRyxDQUFDLEtBQUssRUFBRSxJQUFJO0lBQ3pCLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUNkLENBQUMsQ0FBQSJ9 \ No newline at end of file diff --git a/test/child.ts b/test/child.ts index b3e9ca3..eb5384b 100644 --- a/test/child.ts +++ b/test/child.ts @@ -1,3 +1,5 @@ -import * as smartipc from '../dist/index' - -let localChild = new smartipc.IpcChild({}) \ No newline at end of file +import 'typings-global' +import 'smartq' +module.exports = (input, done) => { + done('hi') +} diff --git a/test/test.js b/test/test.js index 192b419..d7b55c7 100644 --- a/test/test.js +++ b/test/test.js @@ -1,12 +1,26 @@ "use strict"; require("typings-test"); -const should = require("should"); const smartipc = require("../dist/index"); -let testIpcMaster; +let testThreadFunction; +let testThread; describe('smartipc', function () { - it('should create an instance of IpcMaster', function () { - testIpcMaster = new smartipc.IpcMaster({}); - should(testIpcMaster).be.instanceof(smartipc.IpcMaster); + it('should create an instance of ThreadFunction', function () { + testThreadFunction = new smartipc.ThreadFunction((input, done) => { + let url = require('url'); + done(url.parse(input)); + }); + testThreadFunction.send('https://google.com').then(message => { + console.log(message); + testThreadFunction.kill(); + }); + }); + it('should create an instance of Thread', function () { + smartipc.setWorkerBasePath(__dirname); + testThread = new smartipc.Thread('child.js'); + testThread.send('https://google.com').then(message => { + console.log(message); + testThread.kill(); + }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsMENBQXlDO0FBRXpDLElBQUksYUFBaUMsQ0FBQTtBQUVyQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQyx3Q0FBd0MsRUFBQztRQUN4QyxhQUFhLEdBQUcsSUFBSSxRQUFRLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxDQUFBO1FBQzFDLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMzRCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiwwQ0FBeUM7QUFFekMsSUFBSSxrQkFBMkMsQ0FBQTtBQUMvQyxJQUFJLFVBQTJCLENBQUE7QUFFL0IsUUFBUSxDQUFDLFVBQVUsRUFBQztJQUNoQixFQUFFLENBQUMsNkNBQTZDLEVBQUM7UUFDN0Msa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsY0FBYyxDQUFDLENBQUMsS0FBSyxFQUFFLElBQUk7WUFDekQsSUFBSSxHQUFHLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ3hCLElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7UUFDMUIsQ0FBQyxDQUFDLENBQUE7UUFDRixrQkFBa0IsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUN0RCxPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFBO1lBQ3BCLGtCQUFrQixDQUFDLElBQUksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMscUNBQXFDLEVBQUM7UUFDckMsUUFBUSxDQUFDLGlCQUFpQixDQUFDLFNBQVMsQ0FBQyxDQUFBO1FBQ3JDLFVBQVUsR0FBRyxJQUFJLFFBQVEsQ0FBQyxNQUFNLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDNUMsVUFBVSxDQUFDLElBQUksQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLElBQUksQ0FBQyxPQUFPO1lBQzlDLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUE7WUFDcEIsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1FBQ3JCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9 \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 83db778..85e2907 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,13 +1,27 @@ import 'typings-test' -import * as should from 'should' import * as smartipc from '../dist/index' -let testIpcMaster: smartipc.IpcMaster +let testThreadFunction: smartipc.ThreadFunction +let testThread: smartipc.Thread describe('smartipc',function(){ - it('should create an instance of IpcMaster',function(){ - testIpcMaster = new smartipc.IpcMaster({}) - should(testIpcMaster).be.instanceof(smartipc.IpcMaster) + it('should create an instance of ThreadFunction',function(){ + testThreadFunction = new smartipc.ThreadFunction((input, done) => { + let url = require('url') + done(url.parse(input)) + }) + testThreadFunction.send('https://google.com').then(message => { + console.log(message) + testThreadFunction.kill() + }) + }) + it('should create an instance of Thread',function(){ + smartipc.setWorkerBasePath(__dirname) + testThread = new smartipc.Thread('child.js') + testThread.send('https://google.com').then(message => { + console.log(message) + testThread.kill() + }) }) }) diff --git a/ts/index.ts b/ts/index.ts index 0243185..f7a83d8 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,2 +1,2 @@ -export * from './smartipc.classes.ipcmaster' -export * from './smartipc.classes.ipcchild' +export * from './smartipc.classes.thread' +export * from './smartipc.classes.threadfunction' diff --git a/ts/smartipc.classes.thread.ts b/ts/smartipc.classes.thread.ts index 7203b35..ab0c1df 100644 --- a/ts/smartipc.classes.thread.ts +++ b/ts/smartipc.classes.thread.ts @@ -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(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 } - /** - * sends a message to - */ + kill() { + this.thread.kill() + } } \ No newline at end of file diff --git a/ts/smartipc.classes.threadfunction.ts b/ts/smartipc.classes.threadfunction.ts new file mode 100644 index 0000000..c23f451 --- /dev/null +++ b/ts/smartipc.classes.threadfunction.ts @@ -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(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() + } +} diff --git a/ts/smartipc.plugins.ts b/ts/smartipc.plugins.ts new file mode 100644 index 0000000..e3261fb --- /dev/null +++ b/ts/smartipc.plugins.ts @@ -0,0 +1,8 @@ +import 'typings-global' +let threads = require('threads') +import * as smartq from 'smartq' + +export { + smartq, + threads +} diff --git a/ts/smartipc.pool.ts b/ts/smartipc.pool.ts new file mode 100644 index 0000000..e69de29