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

add backpressure support for defaultIfEmpty() #3042

Merged
merged 1 commit into from
Jun 23, 2015

Conversation

davidmoten
Copy link
Collaborator

When looking at implementing backpressure support for defaultIfEmpty the obvious strategy is to reuse switchIfEmpty and get rid of OperatorDefaultIfEmpty. That's what this PR does.

There is a little bit of overhead with using Observable.from(Arrays.asList(defaultValue)) as the alternate observable. Might be nice to have a version of Observable.just(item) that supports backpressure to use in its place (you've mentioned this before @akarnokd).

@akarnokd
Copy link
Member

You could just create an Observable inline:

public final Observable<T> defaultIfEmpty(T defaultValue) {
    //if empty switch to an observable that emits defaultValue and supports backpressure
    return switchIfEmpty(Observable.create(s -> {
        s.setProducer(new SingleProducer<>(defaultValue));
    }));
}

@davidmoten
Copy link
Collaborator Author

Great, can do. I'd like to see that as its own method. I'll put that change in and open another issue so method names/overrides and desirability can be discussed.

@akarnokd
Copy link
Member

Thanks!

akarnokd added a commit that referenced this pull request Jun 23, 2015
add backpressure support for defaultIfEmpty()
@akarnokd akarnokd merged commit c833083 into ReactiveX:1.x Jun 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants