I am a RxSwift beginner and making a app with RxSwift + MVVM.
I have a method which calls API and converts to RxCocoa.Driver in ViewModel class like below.
func fetch() -> Driver<HomeViewEntity> {
apiUseCase.fetch(query: HomeViewQuery())
.map { data in
HomeViewEntity(userName: data.name,
emailAddress: data.email
}
.asDriver(onErrorRecover: { [weak self] error in
if let printableError = error as? PrintableError {
self?.errorMessageRelay.accept(AlertPayload(title: printableError.title, message: printableError.message))
}
return Driver.never()
})
}
Now, I'd like to call this fetchListPlace()
method at regular intervals a.k.a polling (e.g. each 5 minutes) at ViewController.
How to do that????
I think interval
is suit in this case, but I can't get an implementation image....
Here you go:
Also note,
Driver.never()
from your recovery closure is probably a bad idea. PreferDriver.empty()
instead.fetch()
return aDriver<Result<HomeViewEntity, Error>>
instead and move the side effect to the end of the chain (in a subscribe or a flatMap.)