0

Consider the following example:

fun main() {
  Flowable.interval(1, TimeUnit.MILLISECONDS).map {
    Thread.sleep(1000)
    it
  }.blockingForEach { println(it) }
}

Do to missing backpressure, I would expect to get a MissingBackpressureException as written in the docs of Flowable.interval.

What am I getting wrong?

user3612643
  • 5,096
  • 7
  • 34
  • 55
  • By mapping the interval to sleep, you block the call stack so effectively you are producing one item per second, which can be easily processed by blockingForEach in time. – akarnokd Apr 10 '19 at 08:09
  • So I have to switch to another Scheduler before `map`. How do I get back to the previous scheduler after `map`? – user3612643 Apr 10 '19 at 08:23
  • You can only get back if you provide a custom one that uses the same worker thread. The standard schedulers besides `Schedulers.single()` don't help you with that, so you have to create one from an `ExecutorService` via `Schedulers.from()`. Why do you want to get an MBE in the first place? – akarnokd Apr 10 '19 at 08:45
  • I was researching a way to achieve: https://stackoverflow.com/questions/55606278/using-onbackpressurelatest-to-drop-intermediate-messages-in-blocking-flowable – user3612643 Apr 10 '19 at 09:03
  • @akarnokd Would you mind checking the other post, I am getting an `InterruptedException` with `debounce`. – user3612643 Apr 10 '19 at 09:42

0 Answers0