0

When Angular tries to connect, I want to show "Connecting". I can do it on first connect, but I don't know how to do it when using retryWhen(). I need to hook into the actual execution and then do:

this.connectionStatus = "Connecting"

Current code:

    this.connectionStatus = "Connecting";

    let socket = new WebSocketSubject(..);

    this.socket
      .pipe(retryWhen(errors =>
        errors.pipe(
          tap(val => {
            console.log("Retry in 10 sec", val);
          }),
          delay(10000)
        )))
      .subscribe(..);
NoobieNoob
  • 887
  • 2
  • 11
  • 31

1 Answers1

0

Just set the status after delay. retryWhen expect you to return an observable and when this observable emits it'll start retrying connecting i.e start retrying after delay

  errors.pipe(
          tap(val => {
            console.log("Retry in 10 sec", val);
          }),
          delay(10000),
          tap(()=>this.connectionStatus = "Connecting"
)
        )))
Fan Cheung
  • 10,745
  • 3
  • 17
  • 39