let a = PublishSubject
a.asSingle().subscribe(onSuccess: { (_) in
print("asasaa")
}) { (error) in
}.disposed(by: self.disposeBag)
a.onNext(1)
When I call the code above, there is no print.
Is the asSingle() method using errors?
I looked at the code for asSingle() ,
found that I needed to send it myself (. Completed)
So I added take(1) in front of asSingle()
It is required to call take(1) on PublishSubject before calling asSingle:
let subject = PublishSubject<Void>()
subject
.take(1) // Without `take(1)` there is no success event
.asSingle()
.subscribe(onSuccess: { print("success") }, onError: nil)
subject.onNext(())
This is unexpected and may cause bugs.
I looked at the code for asSingle() ,
found that I needed to send it myself (. Completed)
So I added take(1) in front of asSingle()
great! save my time
Most helpful comment
I looked at the code for asSingle() ,
found that I needed to send it myself (. Completed)
So I added take(1) in front of asSingle()