Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use asSingle() #1654

Closed
Z-JaDe opened this issue May 16, 2018 · 3 comments
Closed

use asSingle() #1654

Z-JaDe opened this issue May 16, 2018 · 3 comments

Comments

@Z-JaDe
Copy link

Z-JaDe commented May 16, 2018

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?

@Z-JaDe
Copy link
Author

Z-JaDe commented May 16, 2018

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()

@Z-JaDe Z-JaDe closed this as completed May 16, 2018
@berikv
Copy link

berikv commented Dec 13, 2018

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.

@jokerYellow
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants