title: Issue with condition race issue with Loading Interceptor in Angular
body: <p>I am having a few issues with my loading interceptor and a presumed condition race that is causing this error: <code>Uncaught (in promise) overlay does not exist</code> to appear sometime within my loading interceptor/service.</p>
  <p>Since my app uses numerous (1 to 5) http calls on some pages, I opted to create a interceptor that counted the http requests to present and dismiss the loading overlay. It looks something like this:</p>
  <pre><code>export class LoadingInterceptor implements HttpInterceptor {
  
    private totalRequests = 0;
  
    constructor(private loading: LoadingService) { }
  
    intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
  
      this.totalRequests++;
  
      if (this.totalRequests === 1) {
        this.loading.present();
      }
  
      return next.handle(request).pipe(
        finalize(() =&gt; {
          this.totalRequests--;
          if (this.totalRequests === 0) {
            this.loading.dismiss();
          }
        })
      );
    }
  }
  </code></pre>
  <p>For my loading service, I tried to have the logic check for if the loader was present on the callback using a true/false flag, then either present or dismiss it.</p>
  <pre><code>isLoading = false;
  
    constructor(
      public loadingController: LoadingController
    ) { }
  
    async present() {
      this.isLoading = true;
      return await this.loadingController.create({
        spinner: &quot;circular&quot;,
        translucent: true
      }).then(a =&gt; {
        a.present().then(() =&gt; {
          if (!this.isLoading) {
            a.dismiss().then(() =&gt; this.isLoading = false);
          }
        });
      });
    }
  
    async dismiss() {
      this.isLoading = false;
      return await this.loadingController.dismiss().then(() =&gt; this.isLoading = false);
    }
  </code></pre>
  <p>However, as I mentioned, everyone once in a while, I am still having the condition race issue where the error pops up. Anyone have any thoughts on what may be causing the issue?</p>