title: In Node JS, I have an async operation that does not resolve. How do I use worker thread to abort it?
body: <p>Say I have an async operation like so:</p>
  <pre><code>    async () =&gt; {
         await longTask().then(result =&gt; console.log(result));
      }
  </code></pre>
  <p>Let's say longTask is unpredictable. It hangs and does not resolve some of the time.</p>
  <p>I understand that we can't just abort an async operation.</p>
  <p>I looked into <strong><a href="https://nodejs.org/api/worker_threads.html#worker_threads_worker_terminate" rel="nofollow noreferrer">worker threads</a></strong> so that I can spawn a worker to run this async operation and terminate it if need be.</p>
  <p>Unfortunately when I tried it, the whole program exits.</p>
  <p>Is there a way for me to <strong>abort/terminate/cancel/kill</strong> a worker thread and just remove the async operation, without exiting the node app?</p>
  <p>Thanks for your time.</p>