Skip to content
Advertisement

Process List with synchronous delay after flatMap?

Hey I just started to dive into reactive programming and I can’t figure out how to process a List<String> in a synchronous way after flatMap.

What I am trying to achieve:

  1. Get domain list from external service
  2. Filter out existing domains in database
  3. Make another http request to external service to get domain info. These calls should be executed in a synchronous way with Duration.ofSeconds(new Random().nextInt(5)) delay applied one after another, like Thread.sleep and not in parallel way.
  4. Store new domain data into database
JavaScript

Advertisement

Answer

You might want to wrap that synchronous call in a Mono.fromCallable which yields 0-1 items depending on whether the condition is met or not.

JavaScript

Docs for Flux.delayElements:

JavaScript

I made a small PoC to test this out myself and came up with the following

JavaScript

And the output is as expected:

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