mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Merge pull request #611 from darkdarkdragon/develop-RLJS-535
add timeout logic to Remote.getLedgerSequence
This commit is contained in:
@@ -64,18 +64,20 @@ function getBalanceSheetAsync(address: string, options: BalanceSheetOptions,
|
||||
const requestCallback = composeAsync(
|
||||
formatBalanceSheet, convertErrors(callback));
|
||||
|
||||
this.remote.getLedgerSequence((err, ledgerVersion) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (_.isUndefined(request.ledger_index)) {
|
||||
this.remote.getLedgerSequence((err, ledgerVersion) => {
|
||||
if (err) {
|
||||
convertErrors(callback)(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.isUndefined(request.ledger_index)) {
|
||||
request.ledger_index = ledgerVersion;
|
||||
}
|
||||
|
||||
this.remote.rawRequest(request, requestCallback);
|
||||
});
|
||||
} else {
|
||||
this.remote.rawRequest(request, requestCallback);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getBalanceSheet(address: string, options: BalanceSheetOptions = {}
|
||||
|
||||
@@ -535,13 +535,23 @@ Remote.prototype.getLedgerSequence = function(callback = function() {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
let timeout = null;
|
||||
function onLedgerClosed() {
|
||||
clearTimeout(timeout);
|
||||
callback(null, this._ledger_current_index - 1);
|
||||
}
|
||||
|
||||
if (_.isFinite(this._ledger_current_index)) {
|
||||
// the "current" ledger is the one after the most recently closed ledger
|
||||
callback(null, this._ledger_current_index - 1);
|
||||
} else {
|
||||
this.once('ledger_closed', () => {
|
||||
callback(null, this._ledger_current_index - 1);
|
||||
});
|
||||
this.once('ledger_closed', onLedgerClosed);
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
this.removeListener('ledger_closed', onLedgerClosed);
|
||||
callback(new RippleError('timeout',
|
||||
'Timed out waiting for ledger to close.'));
|
||||
}, this.pathfind_timeout);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user