remove listeners to avoid leaks
This commit is contained in:
parent
2efea55d2b
commit
1b6ac99ea2
|
@ -33,6 +33,7 @@ class Test {
|
|||
this.contracts = {};
|
||||
this.events = new Events();
|
||||
this.ready = true;
|
||||
this.error = false;
|
||||
this.builtContracts = {};
|
||||
this.compiledContracts = {};
|
||||
|
||||
|
@ -111,13 +112,19 @@ class Test {
|
|||
}
|
||||
|
||||
onReady(callback) {
|
||||
const self = this;
|
||||
if (this.ready) {
|
||||
return callback();
|
||||
}
|
||||
if (this.error) {
|
||||
return callback(this.error);
|
||||
}
|
||||
this.events.once('ready', () => {
|
||||
self.events.removeListener('deployError', () => {});
|
||||
callback();
|
||||
});
|
||||
this.events.once('deployError', (err) => {
|
||||
self.events.removeListener('ready', () => {});
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
@ -180,9 +187,11 @@ class Test {
|
|||
self._deploy(options, (err, accounts) => {
|
||||
if (err) {
|
||||
self.events.emit('deployError', err);
|
||||
self.error = err;
|
||||
return next(err);
|
||||
}
|
||||
self.ready = true;
|
||||
self.error = false;
|
||||
self.events.emit('ready');
|
||||
next(null, accounts);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue