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 Observable.executeOn, as alternative to observeOn #164

Closed
alexandru opened this Issue Jun 15, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@alexandru
Copy link
Member

commented Jun 15, 2016

We need an Observable.executeOn operator, as an alternative observeOn from ReactiveX.

Until now Monix hasn't provided this operator because the execution model of Monix is smarter and observeOn seems like a good idea, but it's terribly inefficient and doesn't work like most people think it does.

But there's still the use-case of controlling exactly the scheduler the source executes on, before passing it to consumers and their logic. In Monix the subscriber is always in charge of injecting a Scheduler. But sometimes you want the producer part to happen on a different Scheduler. For example if you're reading from an InputStream, you might want the producer to execute on a special ioScheduler, but when the client executes CPU-bound logic on that generated input, after an async boundary, it makes sense to use the client-injected Scheduler again.

So now executeOn, provided as an alternative:

  • includes the effects of subscribeOn
  • overrides the injected Scheduler for the source

Example:

import monix.execution.Scheduler.Implicits.global

val ioScheduler = ???
val source = Observable.fromInputStream(new FileInputStream(file))
  // All InputStream I/O will now happen on the ioScheduler
  .executeOn(ioScheduler)
  // Introducing an artificial asynchronous boundary, to make sure
  // that further processing will happen on the client's scheduler (i.e. global)
  .asyncBoundary(BackPressured(2048))

In this example, the I/O will be done on the ioScheduler, but further processing / filtering will end up happening on global.

alexandru added a commit that referenced this issue Jun 15, 2016

@alexandru alexandru added this to the 2.0 milestone Jun 15, 2016

@alexandru alexandru self-assigned this Jun 15, 2016

@alexandru

This comment has been minimized.

Copy link
Member Author

commented Jun 15, 2016

Released in 2.0-RC6

@alexandru alexandru closed this Jun 15, 2016

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