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-03-03 19:52:23 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMudGhyZWFkZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIsOENBQTZDO0FBQzdDLDRCQUEyQjtBQU0zQjtJQUVFLFlBQVksV0FBNEI7UUFDdEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtJQUNsRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLENBQUksT0FBWTtRQUNsQixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFLLENBQ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