• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript state-switch.StateSwitch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中state-switch.StateSwitch的典型用法代码示例。如果您正苦于以下问题:TypeScript StateSwitch类的具体用法?TypeScript StateSwitch怎么用?TypeScript StateSwitch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StateSwitch类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: start

  public async start (): Promise<void> {
    log.verbose('IoClient', 'init()')

    if (this.state.pending()) {
      log.warn('IoClient', 'start() with a pending state, not the time')
      const e = new Error('state.pending() when start()')
      throw e
    }

    this.state.on('pending')

    try {

      await this.startIo()
      await this.hookWechaty(this.options.wechaty)

      this.state.on(true)

    } catch (e) {
      log.error('IoClient', 'init() exception: %s', e.message)
      this.state.off(true)
      throw e
    }
    return
  }
开发者ID:zixia,项目名称:wechaty,代码行数:25,代码来源:io-client.ts


示例2: quit

  public async quit (): Promise<void> {
    log.verbose('IoClient', 'quit()')

    if (this.state.off() === 'pending') {
      log.warn('IoClient', 'quit() with state.off() = `pending`, skipped')
      throw new Error('quit() with state.off() = `pending`')
    }

    this.state.off('pending')

    try {
      if (this.options.wechaty) {
        await this.options.wechaty.stop()
        // this.wechaty = null
      } else { log.warn('IoClient', 'quit() no this.wechaty') }

      if (this.io) {
        await this.io.stop()
        // this.io = null
      } else { log.warn('IoClient', 'quit() no this.io') }

    } catch (e) {
      log.error('IoClient', 'exception: %s', e.message)
      throw e
    } finally {
      this.state.off(true)
    }

    return

  }
开发者ID:zixia,项目名称:wechaty,代码行数:31,代码来源:io-client.ts


示例3: start

  public async start(): Promise<void> {
    log.verbose('PuppetPadchatManager', `start()`)

    if (this.userId) {
      throw new Error('userId exist')
    }

    this.state.on('pending')

    if (this.delayQueueExecutorSubscription) {
      throw new Error('this.delayExecutorSubscription exist')
    } else {
      this.delayQueueExecutorSubscription = this.delayQueueExecutor.subscribe(unit => {
        log.verbose('PuppetPadchatManager', 'startQueues() delayQueueExecutor.subscribe(%s) executed', unit.name)
      })
    }

    this.memorySlot = {
      ...this.memorySlot,
      ...await this.options.memory.get<PadchatMemorySlot>(MEMORY_SLOT_NAME),
    }

    /**
     * Sometimes the RPC WebSocket will failure on connect in super.start(),
     *  if that's true then a Error will be throw out.
     *  Try again in the following while loop until the state is not on('pending')
     */
    while (this.state.on() === 'pending') {
      try {
        await super.start()
        break
      } catch (e) {
        log.warn('PuppetPadchatManager', 'start() super.start() exception: %s', e)
        await super.stop()
        await new Promise(r => setTimeout(r, 1000))
        log.warn('PuppetPadchatManager', 'start() super.start() retry now ...')
      }
    }

    await this.tryLoad62Data()

    const succeed = await this.tryAutoLogin(this.memorySlot)
    if (!succeed) {
      await this.startCheckScan()
    }

    this.state.on(true)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:48,代码来源:padchat-manager.ts


示例4: stop

  public async stop (): Promise<void> {
    log.verbose('IoClient', 'stop()')

    this.state.off('pending')

    // XXX
    if (!this.io) {
      log.warn('IoClient', 'stop() without this.io')
      this.state.off(true)
      return
    }

    await this.io.stop()
    this.state.off(true)

    // XXX 20161026
    // this.io = null
    return
  }
开发者ID:zixia,项目名称:wechaty,代码行数:19,代码来源:io-client.ts


示例5: stop

  public async stop(): Promise<void> {
    log.verbose('PuppetPadchatManager', `stop()`)

    this.state.off('pending')

    if (this.delayQueueExecutorSubscription) {
      this.delayQueueExecutorSubscription.unsubscribe()
      this.delayQueueExecutorSubscription = undefined
    } else {
      log.warn('PuppetPadchatManager', 'stop() subscript not exist')
    }

    await this.stopCheckScan()
    await super.stop()
    await this.releaseCache()

    this.userId          = undefined
    this.loginScanQrcode = undefined
    this.loginScanStatus = undefined

    this.state.off(true)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:22,代码来源:padchat-manager.ts


示例6: hookWechaty

  private async hookWechaty (wechaty: Wechaty): Promise<void> {
    log.verbose('IoClient', 'initWechaty()')

    if (this.state.off()) {
      const e = new Error('state.off() is true, skipped')
      log.warn('IoClient', 'initWechaty() %s', e.message)
      throw e
    }

    wechaty
    .on('login'	     , user => log.info('IoClient', `${user.name()} logined`))
    .on('logout'	   , user => log.info('IoClient', `${user.name()} logouted`))
    .on('scan', (url, code) => log.info('IoClient', `[${code}] ${url}`))
    .on('message'     , msg => this.onMessage(msg))

    return
  }
开发者ID:zixia,项目名称:wechaty,代码行数:17,代码来源:io-client.ts


示例7: startIo

  private async startIo (): Promise<void> {
    log.verbose('IoClient', 'startIo() with token %s', this.options.token)

    if (this.state.off()) {
      const e = new Error('startIo() state.off() is true, skipped')
      log.warn('IoClient', e.message)
      throw e
    }

    try {
      await this.io.start()
    } catch (e) {
      log.verbose('IoClient', 'startIo() init fail: %s', e.message)
      throw e
    }

    return
  }
开发者ID:zixia,项目名称:wechaty,代码行数:18,代码来源:io-client.ts


示例8: syncContactsAndRooms

  public async syncContactsAndRooms(): Promise<void> {
    log.verbose('PuppetPadchatManager', `syncContactsAndRooms()`)

    let cont = true
    while (cont && this.state.on() && this.userId) {
      log.silly('PuppetPadchatManager', `syncContactsAndRooms() while() syncing WXSyncContact ...`)

      const syncContactList = await this.WXSyncContact()

      await new Promise(r => setTimeout(r, 10 * 1000))

      if (!Array.isArray(syncContactList) || syncContactList.length <= 0) {
        log.warn('PuppetPadchatManager', 'syncContactsAndRooms() cannot get array result: %s', JSON.stringify(syncContactList))
        continue
      }

      if (   !this.cacheContactRawPayload
          || !this.cacheRoomRawPayload
      ) {
        throw new Error('no cache')
      }

      log.silly('PuppetPadchatManager', 'syncContactsAndRooms() syncing %d out of Contact(%d) & Room(%d) ...',
                                          syncContactList.length,
                                          this.cacheContactRawPayload.size,
                                          this.cacheRoomRawPayload.size,
                  )

      for (const syncContact of syncContactList) {

        if (syncContact.continue !== PadchatContinue.Go) {
          log.verbose('PuppetPadchatManager', 'syncContactsAndRooms() sync contact done!')
          cont = false
          break
        }

        if (syncContact.msg_type === PadchatContactMsgType.Contact) {
          if (isRoomId(syncContact.user_name)) {
            /**
             * Room
             */
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() updating Room %s(%s)',
                        syncContact.nick_name,
                        syncContact.user_name,
            )
            const roomId = syncContact.user_name
            const roomPayload = syncContact as PadchatRoomPayload

            this.cacheRoomRawPayload.set(roomId, roomPayload)

            /**
             * Use delay queue executor to sync room:
             *  add syncRoomMember task to the queue
             */
            await this.delayQueueExecutor.execute(
              () => this.syncRoomMember(roomId),
              `syncRoomMember(${roomId})`,
            )
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() added sync room(%s) task to delayQueueExecutor', roomId)

          } else if (isContactId(syncContact.user_name)) {
            /**
             * Contact
             */
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() updating Contact %s(%s)',
                        syncContact.nick_name,
                        syncContact.user_name,
            )
            const contactPayload = syncContact as PadchatContactPayload
            const contactId = contactPayload.user_name

            this.cacheContactRawPayload.set(contactId, contactPayload)

          } else {
            throw new Error('id is neither room nor contact')
          }
        } else {
          // {"continue":1,"msg_type":2048,"status":1,"uin":4763975}
          if (   syncContact.continue === PadchatContinue.Go
              && syncContact.msg_type === PadchatContactMsgType.N11_2048
              && typeof syncContact.uin !== 'undefined'
          ) {
            // HeartBeat??? discard it in silent
          } else {
            log.silly('PuppetPadchatManager', `syncContactsAndRooms() skip for syncContact.msg_type=%s(%s) %s`,
              syncContact.msg_type && PadchatContactMsgType[syncContact.msg_type],
              syncContact.msg_type,
              JSON.stringify(syncContact),
            )
          }
        }
      }
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:94,代码来源:padchat-manager.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript actions.createStickyAction函数代码示例发布时间:2022-05-25
下一篇:
TypeScript state-switch.off函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap