Avoid conccurent _syncTime calls
This commit is contained in:
@@ -15,6 +15,7 @@ module.exports = class Request {
|
|||||||
constructor(key, secret, livenet=false) {
|
constructor(key, secret, livenet=false) {
|
||||||
this.baseUrl = baseUrls[livenet === true ? 'livenet' : 'testnet'];
|
this.baseUrl = baseUrls[livenet === true ? 'livenet' : 'testnet'];
|
||||||
this._timeOffset = null;
|
this._timeOffset = null;
|
||||||
|
this._syncTimePromise = null;
|
||||||
|
|
||||||
if(key) assert(secret, 'Secret is required for private enpoints');
|
if(key) assert(secret, 'Secret is required for private enpoints');
|
||||||
|
|
||||||
@@ -105,6 +106,18 @@ module.exports = class Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _syncTime() {
|
async _syncTime() {
|
||||||
|
if(this._syncTimePromise !== null) return this._syncTimePromise;
|
||||||
|
|
||||||
|
this._syncTimePromise = new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
this._timeOffset = await this.getTimeOffset();
|
this._timeOffset = await this.getTimeOffset();
|
||||||
|
this._syncTimePromise = null;
|
||||||
|
resolve();
|
||||||
|
} catch(err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return this._syncTimePromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user