0

当 Angular 尝试连接时,我想显示“正在连接”。我可以在第一次连接时做到这一点,但我不知道在使用 retryWhen() 时该怎么做。我需要挂钩实际执行,然后执行:

this.connectionStatus = "Connecting"

当前代码:

    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(..);
4

1 回答 1

0

只需设置延迟后的状态。retryWhen期望您返回一个可观察对象,并且当此可观察对象发出时,它将开始重试连接,即在之后开始重试delay

  errors.pipe(
          tap(val => {
            console.log("Retry in 10 sec", val);
          }),
          delay(10000),
          tap(()=>this.connectionStatus = "Connecting"
)
        )))
于 2019-12-14T09:53:38.877 回答