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) {
const self = this;
ipc.server.on('message', function(data, socket) {
console.dir("received message");
console.dir(action);
console.dir(data);
if (data.action !== action) {
return;
}
done(data.message, socket);
let reply = function(replyData) {
self.reply(socket, 'compile', replyData);
}
done(data.message, reply, socket);
});
}
reply(client, action, data) {
console.dir("reply message");
console.dir(action);
console.dir(data);
ipc.server.emit(client, 'message', {action: action, message: data});
}
once(action, cb) {
ipc.of['embark'].once('message', function(msg) {
console.dir("once message");
console.dir(action);
console.dir(msg);
if (msg.action !== action) {
return;
}
console.dir('received');
cb(msg.message);
});
}
request(action, data) {
console.dir("request message");
console.dir(action);
console.dir(data);
request(action, data, cb) {
if (cb) {
this.once(action, cb);
}
ipc.of['embark'].emit('message', {action: action, message: data});
}

View File

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