當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript utils.intervalUtils類代碼示例

本文整理匯總了TypeScript中@0xproject/utils.intervalUtils的典型用法代碼示例。如果您正苦於以下問題:TypeScript intervalUtils類的具體用法?TypeScript intervalUtils怎麽用?TypeScript intervalUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了intervalUtils類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: startEmittingNetworkConnectionAndUserBalanceState

    public startEmittingNetworkConnectionAndUserBalanceState() {
        if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) {
            return; // we are already emitting the state
        }

        let prevNodeVersion: string;
        this._prevUserEtherBalanceInWei = new BigNumber(0);
        this._dispatcher.updateNetworkId(this._prevNetworkId);
        this._watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(
            async () => {
                // Check for network state changes
                let currentNetworkId;
                try {
                    currentNetworkId = await this._web3Wrapper.getNetworkIdAsync();
                } catch (err) {
                    // Noop
                }
                if (currentNetworkId !== this._prevNetworkId) {
                    this._prevNetworkId = currentNetworkId;
                    this._dispatcher.updateNetworkId(currentNetworkId);
                }

                // Check for node version changes
                const currentNodeVersion = await this._web3Wrapper.getNodeVersionAsync();
                if (currentNodeVersion !== prevNodeVersion) {
                    prevNodeVersion = currentNodeVersion;
                    this._dispatcher.updateNodeVersion(currentNodeVersion);
                }

                if (this._shouldPollUserAddress) {
                    const addresses = await this._web3Wrapper.getAvailableAddressesAsync();
                    const userAddressIfExists = addresses[0];
                    // Update makerAddress on network change
                    if (this._prevUserAddressIfExists !== userAddressIfExists) {
                        this._prevUserAddressIfExists = userAddressIfExists;
                        this._dispatcher.updateUserAddress(userAddressIfExists);
                    }

                    // Check for user ether balance changes
                    if (!_.isUndefined(userAddressIfExists)) {
                        await this._updateUserWeiBalanceAsync(userAddressIfExists);
                    }
                } else {
                    // This logic is primarily for the Ledger, since we don't regularly poll for the address
                    // we simply update the balance for the last fetched address.
                    if (!_.isUndefined(this._prevUserAddressIfExists)) {
                        await this._updateUserWeiBalanceAsync(this._prevUserAddressIfExists);
                    }
                }
            },
            5000,
            (err: Error) => {
                logUtils.log(`Watching network and balances failed: ${err.stack}`);
                this._stopEmittingNetworkConnectionAndUserBalanceStateAsync();
            },
        );
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:57,代碼來源:blockchain_watcher.ts

示例2: _stopBlockAndLogStream

 private _stopBlockAndLogStream(): void {
     if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
         throw new Error(ZeroExError.SubscriptionNotFound);
     }
     this._blockAndLogStreamerIfExists.unsubscribeFromOnLogAdded(this._onLogAddedSubscriptionToken as string);
     this._blockAndLogStreamerIfExists.unsubscribeFromOnLogRemoved(this._onLogRemovedSubscriptionToken as string);
     intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamIntervalIfExists as NodeJS.Timer);
     delete this._blockAndLogStreamerIfExists;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:9,代碼來源:contract_wrapper.ts

示例3: async

 async () => {
     const [balance] = await this.getTokenBalanceAndAllowanceAsync(
         this._userAddressIfExists,
         token.address,
     );
     if (!balance.eq(currBalance)) {
         intervalUtils.clearAsyncExcludingInterval(tokenPollInterval);
         resolve(balance);
     }
 },
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:10,代碼來源:blockchain.ts

示例4: _start

 private _start() {
     this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
         async () => {
             const taskAsync = this._queue.shift();
             if (_.isUndefined(taskAsync)) {
                 return Promise.resolve();
             }
             await taskAsync();
         },
         this._queueIntervalMs,
         (err: Error) => {
             logUtils.log(`Unexpected err: ${err} - ${JSON.stringify(err)}`);
             // tslint:disable-next-line:no-floating-promises
             errorReporter.reportAsync(err);
         },
     );
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:17,代碼來源:dispatch_queue.ts

示例5: Promise

 const newTokenBalancePromise = new Promise((resolve: (balance: BigNumber) => void, reject) => {
     const tokenPollInterval = intervalUtils.setAsyncExcludingInterval(
         async () => {
             const [balance] = await this.getTokenBalanceAndAllowanceAsync(
                 this._userAddressIfExists,
                 token.address,
             );
             if (!balance.eq(currBalance)) {
                 intervalUtils.clearAsyncExcludingInterval(tokenPollInterval);
                 resolve(balance);
             }
         },
         5000,
         (err: Error) => {
             logUtils.log(`Polling tokenBalance failed: ${err}`);
             intervalUtils.clearAsyncExcludingInterval(tokenPollInterval);
             reject(err);
         },
     );
 });
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:20,代碼來源:blockchain.ts

示例6: _startBlockAndLogStream

 private _startBlockAndLogStream(): void {
     if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
         throw new Error(ZeroExError.SubscriptionAlreadyPresent);
     }
     this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
         this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
         this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
     );
     const catchAllLogFilter = {};
     this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter);
     this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval(
         this._reconcileBlockAsync.bind(this),
         constants.DEFAULT_BLOCK_POLLING_INTERVAL,
         this._onReconcileBlockError.bind(this),
     );
     let isRemoved = false;
     this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded(
         this._onLogStateChanged.bind(this, isRemoved),
     );
     isRemoved = true;
     this._onLogRemovedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogRemoved(
         this._onLogStateChanged.bind(this, isRemoved),
     );
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:24,代碼來源:contract_wrapper.ts

示例7: reject

 (err: Error) => {
     logUtils.log(`Polling tokenBalance failed: ${err}`);
     intervalUtils.clearAsyncExcludingInterval(tokenPollInterval);
     reject(err);
 },
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:5,代碼來源:blockchain.ts

示例8: _stopEmittingNetworkConnectionAndUserBalanceStateAsync

 private _stopEmittingNetworkConnectionAndUserBalanceStateAsync() {
     if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) {
         intervalUtils.clearAsyncExcludingInterval(this._watchNetworkAndBalanceIntervalId);
     }
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:5,代碼來源:blockchain_watcher.ts

示例9: stop

 public stop() {
     if (!_.isUndefined(this._queueIntervalIdIfExists)) {
         intervalUtils.clearAsyncExcludingInterval(this._queueIntervalIdIfExists);
     }
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:5,代碼來源:dispatch_queue.ts


注:本文中的@0xproject/utils.intervalUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。