remove listeners to avoid leaks

This commit is contained in:
Iuri Matias 2018-06-08 12:30:44 -04:00
parent 2efea55d2b
commit 1b6ac99ea2
1 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class Test {
this.contracts = {}; this.contracts = {};
this.events = new Events(); this.events = new Events();
this.ready = true; this.ready = true;
this.error = false;
this.builtContracts = {}; this.builtContracts = {};
this.compiledContracts = {}; this.compiledContracts = {};
@ -111,13 +112,19 @@ class Test {
} }
onReady(callback) { onReady(callback) {
const self = this;
if (this.ready) { if (this.ready) {
return callback(); return callback();
} }
if (this.error) {
return callback(this.error);
}
this.events.once('ready', () => { this.events.once('ready', () => {
self.events.removeListener('deployError', () => {});
callback(); callback();
}); });
this.events.once('deployError', (err) => { this.events.once('deployError', (err) => {
self.events.removeListener('ready', () => {});
callback(err); callback(err);
}); });
} }
@ -180,9 +187,11 @@ class Test {
self._deploy(options, (err, accounts) => { self._deploy(options, (err, accounts) => {
if (err) { if (err) {
self.events.emit('deployError', err); self.events.emit('deployError', err);
self.error = err;
return next(err); return next(err);
} }
self.ready = true; self.ready = true;
self.error = false;
self.events.emit('ready'); self.events.emit('ready');
next(null, accounts); next(null, accounts);
}); });