add basic functionality
This commit is contained in:
parent
7c7f2f8b90
commit
78b5412630
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -1,2 +1,2 @@
|
||||
export * from './smartipc.classes.ipcmaster';
|
||||
export * from './smartipc.classes.ipcchild';
|
||||
export * from './smartipc.classes.thread';
|
||||
export * from './smartipc.classes.threadfunction';
|
||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -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
|
||||
__export(require("./smartipc.classes.thread"));
|
||||
__export(require("./smartipc.classes.threadfunction"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsK0NBQXlDO0FBQ3pDLHVEQUFpRCJ9
|
10
dist/smartipc.classes.ipcchild.d.ts
vendored
10
dist/smartipc.classes.ipcchild.d.ts
vendored
@ -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;
|
||||
}
|
15
dist/smartipc.classes.ipcchild.js
vendored
15
dist/smartipc.classes.ipcchild.js
vendored
@ -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=
|
21
dist/smartipc.classes.ipcmaster.d.ts
vendored
21
dist/smartipc.classes.ipcmaster.d.ts
vendored
@ -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;
|
||||
}
|
30
dist/smartipc.classes.ipcmaster.js
vendored
30
dist/smartipc.classes.ipcmaster.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGNtYXN0ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLmlwY21hc3Rlci50cyJdLC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7UUFDckQsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBQ0o7QUEzQkQsOEJBMkJDIn0=
|
15
dist/smartipc.classes.ipctarget.d.ts
vendored
15
dist/smartipc.classes.ipctarget.d.ts
vendored
@ -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;
|
||||
}
|
19
dist/smartipc.classes.ipctarget.js
vendored
19
dist/smartipc.classes.ipctarget.js
vendored
@ -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=
|
10
dist/smartipc.classes.thread.d.ts
vendored
Normal file
10
dist/smartipc.classes.thread.d.ts
vendored
Normal file
@ -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<T>(message: any): Promise<T>;
|
||||
kill(): void;
|
||||
}
|
32
dist/smartipc.classes.thread.js
vendored
Normal file
32
dist/smartipc.classes.thread.js
vendored
Normal file
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLnRocmVhZC50cyJdLCJuYW1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classes.threadfunction.d.ts
vendored
Normal file
@ -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<T>(message: any): Promise<T>;
|
||||
kill(): void;
|
||||
}
|
26
dist/smartipc.classes.threadfunction.js
vendored
Normal file
26
dist/smartipc.classes.threadfunction.js
vendored
Normal file
@ -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
|
6
dist/smartipc.plugins.d.ts
vendored
6
dist/smartipc.plugins.d.ts
vendored
@ -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 };
|
||||
|
9
dist/smartipc.plugins.js
vendored
9
dist/smartipc.plugins.js
vendored
@ -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
|
||||
let threads = require('threads');
|
||||
exports.threads = threads;
|
||||
const smartq = require("smartq");
|
||||
exports.smartq = smartq;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFLNUIsMEJBQU87QUFKWCxpQ0FBZ0M7QUFHNUIsd0JBQU0ifQ==
|
0
dist/smartipc.pool.d.ts
vendored
Normal file
0
dist/smartipc.pool.d.ts
vendored
Normal file
1
dist/smartipc.pool.js
vendored
Normal file
1
dist/smartipc.pool.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucG9vbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBvb2wudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
@ -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"
|
||||
},
|
||||
|
2
test/child.d.ts
vendored
2
test/child.d.ts
vendored
@ -0,0 +1,2 @@
|
||||
import 'typings-global';
|
||||
import 'smartq';
|
@ -1,4 +1,7 @@
|
||||
"use strict";
|
||||
const smartipc = require("../dist/index");
|
||||
let localChild = new smartipc.IpcChild({});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMENBQXlDO0FBRXpDLElBQUksVUFBVSxHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQSJ9
|
||||
require("typings-global");
|
||||
require("smartq");
|
||||
module.exports = (input, done) => {
|
||||
done('hi');
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLGtCQUFlO0FBQ2YsTUFBTSxDQUFDLE9BQU8sR0FBRyxDQUFDLEtBQUssRUFBRSxJQUFJO0lBQ3pCLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUNkLENBQUMsQ0FBQSJ9
|
@ -1,3 +1,5 @@
|
||||
import * as smartipc from '../dist/index'
|
||||
|
||||
let localChild = new smartipc.IpcChild({})
|
||||
import 'typings-global'
|
||||
import 'smartq'
|
||||
module.exports = (input, done) => {
|
||||
done('hi')
|
||||
}
|
||||
|
26
test/test.js
26
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();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsMENBQXlDO0FBRXpDLElBQUksYUFBaUMsQ0FBQTtBQUVyQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQyx3Q0FBd0MsRUFBQztRQUN4QyxhQUFhLEdBQUcsSUFBSSxRQUFRLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxDQUFBO1FBQzFDLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMzRCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQ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Q0FBQSJ9
|
24
test/test.ts
24
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -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
Loading…
Reference in New Issue
Block a user