2016-09-28 23:46:28 +02:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
|
|
|
const smartipc = require("../dist/index");
|
2017-01-29 20:50:36 +01:00
|
|
|
let testThreadFunction;
|
|
|
|
let testThread;
|
2017-01-29 23:41:26 +01:00
|
|
|
let testPool;
|
2016-09-28 23:46:28 +02:00
|
|
|
describe('smartipc', function () {
|
2017-01-29 20:50:36 +01:00
|
|
|
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();
|
|
|
|
});
|
2016-09-28 23:46:28 +02:00
|
|
|
});
|
2017-01-29 23:41:26 +01:00
|
|
|
it('should not spawn when nothing is sent', function () {
|
|
|
|
smartipc.setWorkerBasePath(__dirname);
|
|
|
|
let testThread = new smartipc.Thread('child.js');
|
|
|
|
});
|
|
|
|
it('should run in a Pool', function () {
|
|
|
|
let testPool = new smartipc.Pool();
|
|
|
|
let testThread = new smartipc.Thread('child.js');
|
|
|
|
testThread.assignToPool(testPool);
|
|
|
|
testThread.send('what').then(message => {
|
|
|
|
console.log(message);
|
|
|
|
testThread.send('another').then(message => {
|
|
|
|
console.log(message);
|
|
|
|
testThread.assignedPool.pool.killAll();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-09-28 23:46:28 +02:00
|
|
|
});
|
2017-01-29 23:41:26 +01:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5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