Created
January 3, 2023 08:38
-
-
Save Joony/4d3fd2dcd1087d9a644787a30494f87d to your computer and use it in GitHub Desktop.
A Combine publisher where you can specify a time interval between retries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
extension Publisher { | |
func retryWithDelay<T, E>(retries: Int, interval: DispatchQueue.SchedulerTimeType.Stride) -> Publishers.Catch<Self, AnyPublisher<T, E>> where T == Self.Output, E == Self.Failure { | |
self.catch { error -> AnyPublisher<T, E> in | |
Publishers.Delay( | |
upstream: self, | |
interval: interval, | |
tolerance: 1, | |
scheduler: DispatchQueue.global() | |
) | |
.retry(retries) | |
.eraseToAnyPublisher() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment