title: Project Reactor timeout
body: <p>I am working on a project reactor workshop and am stuck with the following task:</p>
  
  <pre><code>/**
       * TODO 5
       * &lt;p&gt;
       * For each item call received in colors flux call the {@link #simulateRemoteCall} operation.
       * Timeout in case the {@link #simulateRemoteCall} does not return within 400 ms, but retry twice
       * If still no response then provide "default" as a return value
       */
  </code></pre>
  
  <p>The problem I can't wrap my head around is that Flux never actually throws the TimeOutException! I am able to observe this in the console log:</p>
  
  <pre><code>16:05:09.759 [main] INFO Part04HandlingErrors - Received red delaying for 300 
  16:05:09.781 [main] INFO Part04HandlingErrors - Received black delaying for 500 
  16:05:09.782 [main] INFO Part04HandlingErrors - Received tan delaying for 300 
  
  </code></pre>
  
  <p>I tried to play around with the order of the statements, though it didn't seem to change the behaviour. Note: In addition, I tried the overloaded variant of timeout() which accepts a default value that should be returned, if no element is emitted.</p>
  
  <pre><code>public Flux&lt;String&gt; timeOutWithRetry(Flux&lt;String&gt; colors) {
  
          return colors
                  .timeout(Duration.ofMillis(400))
                  //.timeout(Duration.ofMillis(400), Mono.just("default"))
                  .retry(2)
                  .flatMap(this::simulateRemoteCall)
                  .onErrorReturn(TimeoutException.class, "default");
  
      }
  </code></pre>
  
  <p>Can someone clear up why the timeout doesn't occur? I suspect that the mechanism is somehow not "bound" to the method invoked by flatMap.</p>
  
  <p>For completeness: The helper method:</p>
  
  <pre><code>public Mono&lt;String&gt; simulateRemoteCall(String input) {
          int delay = input.length() * 100;
          return Mono.just(input)
                  .doOnNext(s -&gt; log.info("Received {} delaying for {} ", s, delay))
                  .map(i -&gt; "processed " + i)
                  .delayElement(Duration.of(delay, ChronoUnit.MILLIS));
      }
  </code></pre>
  
  <p>More completeness, this is the test I am given to verify the functionality:</p>
  
  <pre><code>@Test
      public void timeOutWithRetry() {
          Flux&lt;String&gt; colors = Flux.just("red", "black", "tan");
  
          Flux&lt;String&gt; results = workshop.timeOutWithRetry(colors);
  
          StepVerifier.create(results).expectNext("processed red", "default", "processed tan").verifyComplete();
      }
  </code></pre>