title: RxJS: How to define a (maximum) duration for an (optional) request?
body: <p>I have this logic:</p>
  
  <pre><code>  public setXXXInLocalStorage(): Observable&lt;boolean&gt; {
  
      return this.appConfig.getEndpoint('xxx')
        .pipe(
          switchMap((endpoint: Endpoint) =&gt; this.http.get(endpoint.toUrl(), {headers})),
          map((body: any) =&gt; { localStorage.setItem('myItem', body.item); }),
          timeout(5000),
          map(() =&gt; true),
          catchError(() =&gt; of(true))
        );
    }
  </code></pre>
  
  <p>What i wanted to achieve is, that i want to wait for max. 5 seconds for my get request.</p>
  
  <ul>
  <li>switchmap: calls my endpoint</li>
  <li>map: deals with the answer</li>
  <li>timeout: i tried to define max. 5 sec. for this call</li>
  <li>map: if success, we should do nothing but just return true</li>
  <li>catchError: if any error occurs from the request, or timeout occurs, we can also simply ignore the error and simply return true</li>
  </ul>
  
  <p>What is now happening is: timeout waits always 5 seconds, even when my get request returns success in 1 sec.</p>
  
  <p>Thanks in advance..</p>