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

Observable vs Flowable on Interfaces With Unknown Implementations #6724

Closed
pixelshaded opened this issue Nov 20, 2019 · 4 comments
Closed

Observable vs Flowable on Interfaces With Unknown Implementations #6724

pixelshaded opened this issue Nov 20, 2019 · 4 comments
Labels

Comments

@pixelshaded
Copy link

@pixelshaded pixelshaded commented Nov 20, 2019

We have a base library which provides interfaces for repository / database access and some basic implementations. In the case of getOne, insert, update, and delete, these all make sense as singles / maybes. However in the case of getAll for instance, this could be a Single<List<Model>> or Observable<Model>. We considered using single, since that's usually how our data is consumed, but these interfaces could hold implementations that support streaming, so using single would essentially prevent those types of implementations from being realized. The consumer can always use the toList operator if they dont want to consume it like a stream or need all the results for business logic.

So now where we are stuck is whether or not these interfaces should return Observables or Flowables. From what I understand, the main difference between the two is that Flowables have added overhead which allow a Consumer to control the rate at which a Producer emits items, where as an Observable does not and will just emit as quickly as possible.

Would it make sense then to always return lower overhead Observables from these interfaces, and to leave it up to the consumer to use toFlowable if they need control over the rate of the Producer? Would this even work or would the Observable consume memory with its unbounded buffer (potential out of memory issues) before being converted to a Flowable which has bounded buffers?

@akarnokd akarnokd added the Question label Nov 20, 2019
@akarnokd

This comment has been minimized.

Copy link
Member

@akarnokd akarnokd commented Nov 20, 2019

You can always unbound Flowable or turn it into a Single. Rebounding an Observable will be still prone to excessive memory usage. There isn't that much of an overhead difference between Flowable and Observable otherwise.

@pixelshaded

This comment has been minimized.

Copy link
Author

@pixelshaded pixelshaded commented Nov 20, 2019

It seems then, based on docs, that Flowable is essentially what Observable was in rxjava1, and now Observables are just an alternative to something like Java8 streams. Is that accurate?

@akarnokd

This comment has been minimized.

Copy link
Member

@akarnokd akarnokd commented Nov 20, 2019

Flowable is essentially what Observable was in rxjava1

Yes.

Observables are just an alternative to something like Java8 streams

No, they are for cases where there can't be a reasonable backpressure (UI events) or backpressure doesn't matter due to short sequences.

@pixelshaded

This comment has been minimized.

Copy link
Author

@pixelshaded pixelshaded commented Nov 20, 2019

Thanks for the quick replies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.