2017-01-29 19:50:36 +00:00
|
|
|
"use strict";
|
2017-03-03 19:52:23 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2017-01-29 19:50:36 +00:00
|
|
|
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;
|
2017-11-28 15:10:15 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMudGhyZWFkZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIsOENBQTZDO0FBQzdDLDRCQUEyQjtBQU0zQjtJQUVFLFlBQVksV0FBNEI7UUFDdEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtJQUNsRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLENBQUksT0FBWTtRQUNsQixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFLLENBQ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