Transforming reactive sequences into blocking structures

The Project Reactor library provides an API for transforming reactive sequences into blocking structures. Even though any blocking operations should be omitted in a reactive application, sometimes it is required by the upper-level API. So, we have the following options for blocking the stream and producing a result synchronously:

  • The toIterable method transforms reactive Flux into a blocking Iterable.
  • The toStream method transforms reactive Flux into a blocking Stream API. As of Reactor 3.2, it uses the toIterable method under the hood.
  • The blockFirst method blocks the current thread until the upstream signals its first value or completes.
  • The blockLast method blocks the current thread until the upstream signals its last value or completes. In the case of the onError signal, it throws the exception in the blocked thread.

It is important to remember that the blockFirst and blockLast operators have method overrides with a duration for which a thread would be blocked. That should prevent infinitely blocked threads. Also, the toIterable and toStream methods are able to use a Queue to store events that may arrive more quickly than the client code iterates blocking Iterable or Stream.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.107.152