refactor to use callbacks on ipc requests

This commit is contained in:
Iuri Matias 2018-06-04 16:39:31 -04:00
parent 37ade68804
commit a57bce2a40
2 changed files with 11 additions and 26 deletions

View File

@ -27,41 +27,35 @@ class IPC {
} }
on(action, done) { on(action, done) {
const self = this;
ipc.server.on('message', function(data, socket) { ipc.server.on('message', function(data, socket) {
console.dir("received message");
console.dir(action);
console.dir(data);
if (data.action !== action) { if (data.action !== action) {
return; return;
} }
done(data.message, socket); let reply = function(replyData) {
self.reply(socket, 'compile', replyData);
}
done(data.message, reply, socket);
}); });
} }
reply(client, action, data) { reply(client, action, data) {
console.dir("reply message");
console.dir(action);
console.dir(data);
ipc.server.emit(client, 'message', {action: action, message: data}); ipc.server.emit(client, 'message', {action: action, message: data});
} }
once(action, cb) { once(action, cb) {
ipc.of['embark'].once('message', function(msg) { ipc.of['embark'].once('message', function(msg) {
console.dir("once message");
console.dir(action);
console.dir(msg);
if (msg.action !== action) { if (msg.action !== action) {
return; return;
} }
console.dir('received');
cb(msg.message); cb(msg.message);
}); });
} }
request(action, data) { request(action, data, cb) {
console.dir("request message"); if (cb) {
console.dir(action); this.once(action, cb);
console.dir(data); }
ipc.of['embark'].emit('message', {action: action, message: data}); ipc.of['embark'].emit('message', {action: action, message: data});
} }

View File

@ -39,11 +39,7 @@ class SolcW {
}); });
this.ipc.serve(); this.ipc.serve();
this.ipc.on('compile', (data, client) => { this.ipc.on('compile', self.compile.bind(this));
self.compile(data, (result) => {
self.ipc.reply(client, 'compilation', result);
});
});
this.events.request("version:get:solc", function(solcVersion) { this.events.request("version:get:solc", function(solcVersion) {
if (solcVersion === currentSolcVersion) { if (solcVersion === currentSolcVersion) {
@ -69,12 +65,7 @@ class SolcW {
let a = new Date(); let a = new Date();
if (this.useIpc) { if (this.useIpc) {
this.ipc.once('compilation', (data) => { return this.ipc.request('compile', jsonObj, done);
done(data);
});
this.ipc.request('compile', jsonObj);
return;
} }
this.solcProcess.once('result', 'compilation-' + id, (msg) => { this.solcProcess.once('result', 'compilation-' + id, (msg) => {