Это была топи c беседы на Использование комбината репо проекта некоторое время назад - весь поток: https://github.com/heckj/swiftui-notes/issues/164.
Длинный Короче говоря, мы сделали пример, который, я думаю, делает то, что вы хотите, хотя он использует catch
:
let resultPublisher = upstreamPublisher.catch { error -> AnyPublisher<String, Error> in
return Publishers.Delay(upstream: upstreamPublisher,
interval: 3,
tolerance: 1,
scheduler: DispatchQueue.global())
// moving retry into this block reduces the number of duplicate requests
// In effect, there's the original request, and the `retry(2)` here will operate
// two additional retries on the otherwise one-shot publisher that is initiated with
// the `Publishers.Delay()` just above. Just starting this publisher with delay makes
// an additional request, so the total number of requests ends up being 4 (assuming all
// fail). However, no delay is introduced in this sequence if the original request
// is successful.
.retry(2)
.eraseToAnyPublisher()
}
Это ссылка на шаблон повторения , который я имею в книге / онлайн , который, по сути, является тем, что вы описываете (но не то, о чем вы спрашивали).
человек, с которым я переписывался по вопросу , предоставил вариант в этой теме в качестве расширения это также может быть интересно:
extension Publisher {
func retryWithDelay<T, E>()
-> Publishers.Catch<Self, AnyPublisher<T, E>> where T == Self.Output, E == Self.Failure
{
return self.catch { error -> AnyPublisher<T, E> in
return Publishers.Delay(
upstream: self,
interval: 3,
tolerance: 1,
scheduler: DispatchQueue.global()).retry(2).eraseToAnyPublisher()
}
}
}