2016-09-28 21:46:28 +00:00
|
|
|
"use strict";
|
2017-03-03 19:52:23 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2016-09-28 21:46:28 +00:00
|
|
|
require("typings-test");
|
2017-03-03 19:52:23 +00:00
|
|
|
const smartchai_1 = require("smartchai");
|
2016-09-28 21:46:28 +00:00
|
|
|
const smartipc = require("../dist/index");
|
2017-01-29 19:50:36 +00:00
|
|
|
let testThreadFunction;
|
|
|
|
let testThread;
|
2017-01-29 22:41:26 +00:00
|
|
|
let testPool;
|
2016-09-28 21:46:28 +00:00
|
|
|
describe('smartipc', function () {
|
2017-01-29 19:50:36 +00: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 21:46:28 +00:00
|
|
|
});
|
2017-01-29 22:41:26 +00: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);
|
2017-03-03 19:52:23 +00:00
|
|
|
return testThread.send('what').then(message => {
|
2017-01-29 22:41:26 +00:00
|
|
|
console.log(message);
|
2017-03-03 19:52:23 +00:00
|
|
|
return testThread.send('another').then(message => {
|
2017-01-29 22:41:26 +00:00
|
|
|
console.log(message);
|
|
|
|
testThread.assignedPool.pool.killAll();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-03 19:52:23 +00:00
|
|
|
it('should once', function () {
|
|
|
|
let testThread = new smartipc.Thread('child.js');
|
|
|
|
return testThread.sendOnce('what').then(message => {
|
|
|
|
smartchai_1.expect(message).to.equal('what');
|
|
|
|
});
|
|
|
|
});
|
2016-09-28 21:46:28 +00:00
|
|
|
});
|
2017-03-03 19:52:23 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3QkFBcUI7QUFDckIseUNBQWtDO0FBRWxDLDBDQUF5QztBQUV6QyxJQUFJLGtCQUEyQyxDQUFBO0FBQy9DLElBQUksVUFBMkIsQ0FBQTtBQUMvQixJQUFJLFFBQXVCLENBQUE7QUFFM0IsUUFBUSxDQUFDLFVBQVUsRUFBRTtJQUNuQixFQUFFLENBQUMsNkNBQTZDLEVBQUU7UUFDaEQsa0JBQWtCLEdBQUcsSUFBSSxRQUFRLENBQUMsY0FBYyxDQUFDLENBQUMsS0FBSyxFQUFFLElBQUk7WUFDM0QsSUFBSSxHQUFHLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ3hCLElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7UUFDeEIsQ0FBQyxDQUFDLENBQUE7UUFDRixrQkFBa0IsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUN4RCxPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFBO1lBQ3BCLGtCQUFrQixDQU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