WebSocket Improvments #3544

This commit is contained in:
Nicolas Gotchac
2016-11-23 17:37:04 +01:00
parent a22469ade5
commit f800dd1eee
5 changed files with 193 additions and 55 deletions

View File

@@ -21,25 +21,39 @@ export default class Registry {
this._api = api;
this._contracts = [];
this._instance = null;
this._fetching = false;
this._queue = [];
this.getInstance();
}
getInstance () {
return new Promise((resolve, reject) => {
if (this._instance) {
resolve(this._instance);
return;
}
if (this._instance) {
return Promise.resolve(this._instance);
}
this._api.parity
.registryAddress()
.then((address) => {
this._instance = this._api.newContract(abis.registry, address).instance;
resolve(this._instance);
})
.catch(reject);
});
if (this._fetching) {
return new Promise((resolve) => {
this._queue.push({ resolve });
});
}
this._fetching = true;
return this._api.parity
.registryAddress()
.then((address) => {
this._fetching = false;
this._instance = this._api.newContract(abis.registry, address).instance;
this._queue.forEach((queued) => {
queued.resolve(this._instance);
});
this._queue = [];
return this._instance;
});
}
getContract (_name) {