There are two problems with this piece of code:
- it blocks the current thread - Monix is always defaulting to process things synchronously and you might argue that this
timeoutOnSlowDownstream
operator violates the principle of least surprise, but if you want the timeout to work, it must not block the thread that executesonNext
- consider that on top of Javascript it's not even possible
So it is better doing this and the timeout will get triggered:
def onNext(elem: Int) = Future {
sum += elem
Thread.sleep(20000)