private handleError()

in src/watch.ts [268:287]


  private handleError(err: Error) {
    if (this.state === State.Connected) {
      this.queue!.destroy();
      this.getStream().cancel();
    }
    this.state = State.Idle;

    this.watchers.forEach(watcher => {
      watcher.emit('disconnected', err);
      (watcher as { id: null }).id = null;
    });

    setTimeout(() => {
      if (this.state === State.Idle) {
        this.establishStream();
      }
    }, this.backoff.duration());

    this.backoff = this.backoff.next() ?? this.backoff;
  }