This commit is contained in:
Iuri Matias 2019-05-02 07:58:46 -04:00
parent 1fcfaad5f4
commit c725f2878f
2 changed files with 29 additions and 8 deletions

View File

@ -8,14 +8,15 @@ class GraphGenerator {
this.events = embark.events; this.events = embark.events;
this.contracts = []; this.contracts = [];
this.events.setCommandHandler("graph:create", function(options, cb) { this.events.setCommandHandler("graph:create", async function(options, cb) {
self.generate(options); await self.generate(options);
console.dir("generate done")
cb(); cb();
}); });
} }
/*eslint complexity: ["error", 21]*/ /*eslint complexity: ["error", 21]*/
generate(options) { async generate(options) {
const self = this; const self = this;
let id = 0; let id = 0;
let contractString = ""; let contractString = "";
@ -24,8 +25,15 @@ class GraphGenerator {
let contractInheritance = {}; let contractInheritance = {};
let contractsDependencies = {}; let contractsDependencies = {};
console.dir("-- getContractList");
self.contracts = await self.events.get('contracts:list');
console.dir("-- getContractList done");
async.waterfall([ async.waterfall([
function getContractList(next) { function getContractList(next) {
// self.contracts = await self.events.get('contracts:list');
// console.dir("getContractList done");
// next();
self.events.request('contracts:list', (err, contracts) => { self.events.request('contracts:list', (err, contracts) => {
self.contracts = contracts; self.contracts = contracts;
next(); next();

View File

@ -70,18 +70,31 @@ EventEmitter.prototype.request = function() {
}; };
EventEmitter.prototype.get = function() { EventEmitter.prototype.get = function() {
let self = this;
let requestName = arguments[0]; let requestName = arguments[0];
let other_args = [].slice.call(arguments, 1); let other_args = [].slice.call(arguments, 1);
log("get: ", requestName); log("get: ", requestName);
warnIfLegacy(requestName); warnIfLegacy(requestName);
const listenerName = 'get:' + requestName; const listenerName = 'request:' + requestName;
let promise = new Promise((resolve, reject) => { let promise = new Promise(function(resolve, reject) {
return this.emit(listenerName, ...other_args, (err, res) => { let cb = (err, res) => {
if (err) return reject(err); console.dir("got response!")
console.dir("err")
console.dir("res")
console.dir(res)
if (err) {
console.dir("rejecting")
console.dir(err)
return reject(err);
}
console.dir("resolving")
console.dir(res)
return resolve(res); return resolve(res);
}) }
other_args.push(cb);
return self.emit(listenerName, ...other_args)
}); });
return promise; return promise;