How to use the state-switch.StateSwitch function in state-switch

To help you get started, we’ve selected a few state-switch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github huan / flash-store / src / flash-store-sync.ts View on Github external
constructor(
    public workdir?: string,
  ) {
    log.verbose('CacheStore', 'constructor(%s)', workdir)

    workdir = workdir || '.flash-store-sync'

    this.asyncBusyDict = {}
    this.asyncBusyState   = new StateSwitch(
      'Busy:' + workdir.split('/').pop(), // get the latest folder name
      log,
    )

    this.cacheMap   = new Map()
    this.flashStore = new FlashStore(workdir)

    this.asyncBusyAdd(this.loadStoreToCache())

  }
github wechaty / wechaty / src / io.ts View on Github external
interface IoEventAny {
  name:     IoEventName,
  payload:  any,
}

type IoEvent = IoEventScan | IoEventAny

export class Io {

  private readonly id       : string
  private readonly protocol : string
  private eventBuffer       : IoEvent[] = []
  private ws                : undefined | WebSocket

  private readonly state = new StateSwitch('Io', log)

  private reconnectTimer?   : NodeJS.Timer
  private reconnectTimeout? : number

  private lifeTimer? : NodeJS.Timer

  private onMessage: undefined | AnyFunction

  private scanPayload?: PuppetQrcodeScanEvent

  constructor (
    private options: IoOptions,
  ) {
    options.apihost   = options.apihost   || config.apihost
    options.protocol  = options.protocol  || config.default.DEFAULT_PROTOCOL
github wechaty / wechaty / src / puppet-padchat / padchat-manager.ts View on Github external
constructor(
    public options: ManagerOptions,
  ) {
    super(options.endpoint, options.token)
    log.verbose('PuppetPadchatManager', 'constructor()')

    this.memorySlot = {
      device: {},
    }

    this.state = new StateSwitch('PuppetPadchatManager')

    /**
     * Executer Queue: execute one task at a time,
     *  delay between them for 15 second
     */
    this.delayQueueExecutor = new DelayQueueExector(1000 * 15)

  }
github wechaty / wechaty / src / io-client.ts View on Github external
constructor (
    public options: IoClientOptions,
  ) {
    log.verbose('IoClient', 'constructor(%s)', JSON.stringify(options))

    this.state = new StateSwitch('IoClient', log)

    this.io = new Io({
      token   : this.options.token,
      wechaty : this.options.wechaty,
    })

  }

state-switch

State Switch is a Change Monitor/Guarder for Async Actions.

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular state-switch functions