From c725f2878f36898bbfe10083a13ce3918e050661 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 2 May 2019 07:58:46 -0400 Subject: [PATCH] test --- packages/embark-graph/src/index.js | 14 +++++++++++--- packages/embark/src/lib/core/events.js | 23 ++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/embark-graph/src/index.js b/packages/embark-graph/src/index.js index bcd4e11e2..1ab5a23cc 100644 --- a/packages/embark-graph/src/index.js +++ b/packages/embark-graph/src/index.js @@ -8,14 +8,15 @@ class GraphGenerator { this.events = embark.events; this.contracts = []; - this.events.setCommandHandler("graph:create", function(options, cb) { - self.generate(options); + this.events.setCommandHandler("graph:create", async function(options, cb) { + await self.generate(options); + console.dir("generate done") cb(); }); } /*eslint complexity: ["error", 21]*/ - generate(options) { + async generate(options) { const self = this; let id = 0; let contractString = ""; @@ -24,8 +25,15 @@ class GraphGenerator { let contractInheritance = {}; let contractsDependencies = {}; + console.dir("-- getContractList"); + self.contracts = await self.events.get('contracts:list'); + console.dir("-- getContractList done"); + async.waterfall([ function getContractList(next) { + // self.contracts = await self.events.get('contracts:list'); + // console.dir("getContractList done"); + // next(); self.events.request('contracts:list', (err, contracts) => { self.contracts = contracts; next(); diff --git a/packages/embark/src/lib/core/events.js b/packages/embark/src/lib/core/events.js index 16e2858aa..614609642 100644 --- a/packages/embark/src/lib/core/events.js +++ b/packages/embark/src/lib/core/events.js @@ -70,18 +70,31 @@ EventEmitter.prototype.request = function() { }; EventEmitter.prototype.get = function() { + let self = this; let requestName = arguments[0]; let other_args = [].slice.call(arguments, 1); log("get: ", requestName); warnIfLegacy(requestName); - const listenerName = 'get:' + requestName; + const listenerName = 'request:' + requestName; - let promise = new Promise((resolve, reject) => { - return this.emit(listenerName, ...other_args, (err, res) => { - if (err) return reject(err); + let promise = new Promise(function(resolve, reject) { + let cb = (err, res) => { + 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); - }) + } + other_args.push(cb); + return self.emit(listenerName, ...other_args) }); return promise;