当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript intervalUtils.setAsyncExcludingInterval方法代码示例

本文整理汇总了TypeScript中@0xproject/utils.intervalUtils.setAsyncExcludingInterval方法的典型用法代码示例。如果您正苦于以下问题:TypeScript intervalUtils.setAsyncExcludingInterval方法的具体用法?TypeScript intervalUtils.setAsyncExcludingInterval怎么用?TypeScript intervalUtils.setAsyncExcludingInterval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@0xproject/utils.intervalUtils的用法示例。


在下文中一共展示了intervalUtils.setAsyncExcludingInterval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _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

示例3: 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

示例4: _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


注:本文中的@0xproject/utils.intervalUtils.setAsyncExcludingInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。