Skip to content
Advertisement

Java reactor how to properly start async cancellable sideeffect

I’m trying to write something using reactor which I know how to write using completable futures. I’m getting “Calling subscribe in non-blocking scope” warning in it.

My goal is to call turnOn() with a timeout which should call turnOff() after the timeout. If turnOn() is called again it should cancel the old timeout and wait for a new timeout.

How should I do this? I could do a hibrate and use CompletableFuture for the timeout but reactor’s api is just a bit easier.

this test works as expected:

JavaScript

but my reactor code does not.

JavaScript

Advertisement

Answer

The problem lies in the mapping to void mono’s in the turnOn() and turnOff() methods. They do not actually get a “next” signal, just a “success” signal.

The fix is simply to change the turnOn method to:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement