typescriptrxjspipe

delayWhen vs delay difference in a specific use case


Let's say I built a pipe that contains a retryWhen in the end to catch the errors. What's the difference between

retryWhen(err => {
        return err.pipe(
            tap(() => {console.log(`retrying...`)}),
            delayWhen(() => timer(2000))
        )
    })

and

retryWhen(err => {
        return err.pipe(
            tap(() => {console.log(`retrying...`)}),
            delay(2000)
        )
    })

besides the different usage of the two operators?


Solution

  • In this case there's no difference between them, both return an Observable that emits after 2 seconds. You might prefer delay as it's more explicit.