本文整理汇总了TypeScript中state-switch.StateSwitch.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript StateSwitch.on方法的具体用法?TypeScript StateSwitch.on怎么用?TypeScript StateSwitch.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state-switch.StateSwitch
的用法示例。
在下文中一共展示了StateSwitch.on方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: 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)
}
示例3: 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),
)
}
}
}
}
}