Saturday, October 14, 2023
HomeiOS Developmentios - RxSwift) situation with subscribing to a completable occasion utilizing flatMap

ios – RxSwift) situation with subscribing to a completable occasion utilizing flatMap


func someCompletable() -> Completable {
    return Completable.create { observer in
        observer(.accomplished)
        return Disposables.create()
    }
}
let buttonDidTap = PublishRelay<Void>()

buttonDidTap
    .debug()
    .subscribe()
    .disposed(by: disposeBag)

I see that the following() occasion is fired when the buttonDidTap is tapped.

Nevertheless, once I convert it to the Completable kind by way of flatMap, no occasions are emitted after flatMap.

buttonDidTap
    .flatMap { self.someCompletable() } 
    .debug()
    .subscribe()
    .disposed(by: disposeBag)

I’ve additionally tried subscribing to all of the occasions onNext, onCompletable, onError, and onDisposed, however none of them are emitted.
Any thought why that is?

Here is a gif run display for this
: https://user-images.githubusercontent.com/57667738/229386647-c061d185-2015-40af-9150-5daac58c47ec.gif

buttonDidTap
    .debug() //onNext occasion fired
    .flatMap { self.someCompletable() } 
    .debug() //no occasion fired
    .subscribe()
    .disposed(by: disposeBag)

My guess is that the flatMap loses the Completable traits within the technique of changing a Completable to an Observable and reverts to the type of an Observable.
Subsequently, the decision to onCompleted appears to vanish.
How can I clear up this drawback?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments