当前位置: 首页>>代码示例>>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;未经允许,请勿转载。