Tried these "solutions":
Combine framework retry after delay?
https://www.donnywals.com/retrying-a-network-request-with-a-delay-in-combine/
But all of them doesn't work:
let retryCount = 3
let delay = 5
func requestOneTime() -> Future<(), Error> { ... }
requestOneTime()
.eraseToAnyPublisher()
.retryWithDelay(retries: retryCount, delay: delay, scheduler: DispatchQueue.global())
The result is always the same:
Instance method 'delay(for:tolerance:scheduler:options:)' requires that 'DispatchObject' conform to 'Scheduler'
or
Instance method 'retryWithDelay(retries:delay:scheduler:)' requires that 'DispatchObject' conform to 'Scheduler'
I even tried to retry URLSession.shared.dataTaskPublisher with delay - the result is the same too. Why nothing works? Is caused by a minimum supported version in the project (iOS 13)?
UPDATED
Figured out that this code doesn't work:
.retryWithDelay(retries: retryCount, delay: delay, scheduler: DispatchQueue.global())
but this code works:
.retryWithDelay(retries: retryCount, delay: 5, scheduler: DispatchQueue.global())
but if it is a typical type mismatch then how to declare delay variable of type S.SchedulerTimeType.Stride correctly?
If you are using
DispatchQueue.global()as the scheduler, thenSisDispatchQueue, and soS.SchedulerTimeType.StrideisDispatchQueue.SchedulerTimeType.Stride. This is a struct declared inDispatchQueue.SchedulerTimeType, notInt.Incidentally,
DispatchQueue.SchedulerTimeType.Strideconforms toExpressibleByIntegerLiteral. That's why passing5directly works, since5is an integer literal.If you want to declare a named constant for the delay, explicitly statethe type
DispatchQueue.SchedulerTimeType.Stride.Alternatively,
or keep
delayas anInt, and pass.seconds(delay)instead.