0

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?

Gargo
  • 1,135
  • 1
  • 10
  • 21
  • I cannot reproduce the error, using the solution in the first link. – Sweeper Jun 30 '23 at 07:38
  • @Sweeper found out that this error is caused by type mismatch but I still don't know how to declare the variable of this type correctly. – Gargo Jun 30 '23 at 07:55

1 Answers1

1

If you are using DispatchQueue.global() as the scheduler, then S is DispatchQueue, and so S.SchedulerTimeType.Stride is DispatchQueue.SchedulerTimeType.Stride. This is a struct declared in DispatchQueue.SchedulerTimeType, not Int.

Incidentally, DispatchQueue.SchedulerTimeType.Stride conforms to ExpressibleByIntegerLiteral. That's why passing 5 directly works, since 5 is an integer literal.

If you want to declare a named constant for the delay, explicitly statethe type DispatchQueue.SchedulerTimeType.Stride.

let delay: DispatchQueue.SchedulerTimeType.Stride = 5

Alternatively,

let delay: DispatchQueue.SchedulerTimeType.Stride = .seconds(5)

or keep delay as an Int, and pass .seconds(delay) instead.

Sweeper
  • 213,210
  • 22
  • 193
  • 313