title: How to reject child Promise using AbortController
body: <p>I just learned about how to reject a Promise by using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController" rel="nofollow noreferrer">AbortController API</a>. It's working fine but when the promise to reject as a &quot;child Promise&quot;, this one will still continue running even if the parent Promise is rejected.</p>
  <p>Is there a way, when the parent is rejected, to stop the children too?</p>
  <p>In this example, this means that there is no more <code>running</code> log after the <code>rejected</code> log when you click on the cancel button:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let controller = new AbortController();
  
  new Promise((resolve, reject) =&gt; {
    setInterval(() =&gt; console.log("running"), 500)
  
    controller.signal.addEventListener('abort', () =&gt; {
      console.log("rejected")
      reject();
    });
  
  });
  
  function cancel() {
    controller.abort();
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button onclick="cancel()"&gt;Cancel async loop&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>