_getInternalBlockNumber(maxAge) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this._ready();
            // Allowing stale data up to maxAge old
            if (maxAge > 0) {
                // While there are pending internal block requests...
                while (this._internalBlockNumber) {
                    // ..."remember" which fetch we started with
                    const internalBlockNumber = this._internalBlockNumber;
                    try {
                        // Check the result is not too stale
                        const result = yield internalBlockNumber;
                        if ((getTime() - result.respTime) <= maxAge) {
                            return result.blockNumber;
                        }
                        // Too old; fetch a new value
                        break;
                    }
                    catch (error) {
                        // The fetch rejected; if we are the first to get the
                        // rejection, drop through so we replace it with a new
                        // fetch; all others blocked will then get that fetch
                        // which won't match the one they "remembered" and loop
                        if (this._internalBlockNumber === internalBlockNumber) {
                            break;
                        }
                    }
                }
            }
            const reqTime = getTime();
            const checkInternalBlockNumber = resolveProperties({
                blockNumber: this.perform("getBlockNumber", {}),
                networkError: this.getNetwork().then((network) => (null), (error) => (error))
            }).then(({ blockNumber, networkError }) => {
                if (networkError) {
                    // Unremember this bad internal block number
                    if (this._internalBlockNumber === checkInternalBlockNumber) {
                        this._internalBlockNumber = null;
                    }
                    throw networkError;
                }
                const respTime = getTime();
                blockNumber = BigNumber.from(blockNumber).toNumber();
                if (blockNumber < this._maxInternalBlockNumber) {
                    blockNumber = this._maxInternalBlockNumber;
                }
                this._maxInternalBlockNumber = blockNumber;
                this._setFastBlockNumber(blockNumber); // @TODO: Still need this?
                return { blockNumber, reqTime, respTime };
            });
            this._internalBlockNumber = checkInternalBlockNumber;
            // Swallow unhandled exceptions; if needed they are handled else where
            checkInternalBlockNumber.catch((error) => {
                // Don't null the dead (rejected) fetch, if it has already been updated
                if (this._internalBlockNumber === checkInternalBlockNumber) {
                    this._internalBlockNumber = null;
                }
            });
            return (yield checkInternalBlockNumber).blockNumber;
        });
    }
// than maxAge old or has been requested since the last request
than maxAge old or has been requested since the last request
than maxAge old or has been requested since the last request
_getInternalBlockNumber(maxAge) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this._ready();
            if (maxAge > 0) {
                while (this._internalBlockNumber) {
                    const internalBlockNumber = this._internalBlockNumber;
                    try {
                        const result = yield internalBlockNumber;
                        if ((getTime() - result.respTime) <= maxAge) {
                            return result.blockNumber;
                        }
                        break;
                    }
                    catch (error) {
                        if (this._internalBlockNumber === internalBlockNumber) {
                            break;
                        }
                    }
                }
            }
            const reqTime = getTime();
            const checkInternalBlockNumber = resolveProperties({
                blockNumber: this.perform("getBlockNumber", {}),
                networkError: this.getNetwork().then((network) => (null), (error) => (error))
            }).then(({ blockNumber, networkError }) => {
                if (networkError) {
                    if (this._internalBlockNumber === checkInternalBlockNumber) {
                        this._internalBlockNumber = null;
                    }
                    throw networkError;
                }
                const respTime = getTime();
                blockNumber = BigNumber.from(blockNumber).toNumber();
                if (blockNumber < this._maxInternalBlockNumber) {
                    blockNumber = this._maxInternalBlockNumber;
                }
                this._maxInternalBlockNumber = blockNumber;
                this._setFastBlockNumber(blockNumber); 
                return { blockNumber, reqTime, respTime };
            });
            this._internalBlockNumber = checkInternalBlockNumber;
            checkInternalBlockNumber.catch((error) => {
                if (this._internalBlockNumber === checkInternalBlockNumber) {
                    this._internalBlockNumber = null;
                }
            });
            return (yield checkInternalBlockNumber).blockNumber;
        });
    }
_getInternalBlockNumber ( maxAge ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { yield this . _ready ( ) ; if ( maxAge > 0 ) { while ( this . _internalBlockNumber ) { const internalBlockNumber = this . _internalBlockNumber ; try { const result = yield internalBlockNumber ; if ( ( getTime ( ) - result . respTime ) <= maxAge ) { return result . blockNumber ; } break ; } catch ( error ) { if ( this . _internalBlockNumber === internalBlockNumber ) { break ; } } } } const reqTime = getTime ( ) ; const checkInternalBlockNumber = resolveProperties ( { blockNumber : this . perform ( "getBlockNumber" , { } ) , networkError : this . getNetwork ( ) . then ( ( network ) => ( null ) , ( error ) => ( error ) ) } ) . then ( ( { blockNumber , networkError } ) => { if ( networkError ) { if ( this . _internalBlockNumber === checkInternalBlockNumber ) { this . _internalBlockNumber = null ; } throw networkError ; } const respTime = getTime ( ) ; blockNumber = BigNumber . from ( blockNumber ) . toNumber ( ) ; if ( blockNumber < this . _maxInternalBlockNumber ) { blockNumber = this . _maxInternalBlockNumber ; } this . _maxInternalBlockNumber = blockNumber ; this . _setFastBlockNumber ( blockNumber ) ; return { blockNumber , reqTime , respTime } ; } ) ; this . _internalBlockNumber = checkInternalBlockNumber ; checkInternalBlockNumber . catch ( ( error ) => { if ( this . _internalBlockNumber === checkInternalBlockNumber ) { this . _internalBlockNumber = null ; } } ) ; return ( yield checkInternalBlockNumber ) . blockNumber ; } ) ; }
than maxAge old or has been requested since the last request
than maxAge old or has been requested since the last request
// Allowing stale data up to maxAge old // While there are pending internal block requests... // ..."remember" which fetch we started with // Check the result is not too stale // Too old; fetch a new value // The fetch rejected; if we are the first to get the // rejection, drop through so we replace it with a new // fetch; all others blocked will then get that fetch // which won't match the one they "remembered" and loop // Unremember this bad internal block number // @TODO: Still need this? // Swallow unhandled exceptions; if needed they are handled else where // Don't null the dead (rejected) fetch, if it has already been updated