Launched March 4, 2025
@wjfe/async-workers

@wjfe/async-workers

Thread-safe cancellation and synchronization for web workers!

FreeAPIUI LibraryHelpers1,861 impressions#18 of its week

Before today, the only way to abort the work being done by a web worker was to terminate the worker. This is inconvenient because: - Data may be lost that would have to be re-transmitted to a new worker instance after termination. - Shared workers cannot be terminated. This NPM package can provide a cancellation token based on Atomics.

Thread-safe cancellation and synchronization for Web Workers via Atomics

for
Web developers needing safe abort of worker tasks
pricing
open source
license
MIT
WJSoftware/wjfe-async-workers 11 0TypeScriptupdated a month ago
works withWeb WorkersAtomics

Key features

4 features of wjfe/async-workers
  • Cancellation Token — Provides a token to abort worker tasks without terminating the worker
  • Thread-Safe Sync — Uses Atomics for safe synchronization across workers
  • NodeJS Support — Works in Node via a Worker polyfill like web-worker
  • Cross-Origin Awareness — Handles environments without cross-origin isolation gracefully

Use cases

  • Abort a long-running prime-number calculation in a shared worker
  • Prevent data loss when restarting a worker after cancellation
  • Synchronize multiple tasks using Atomics in a NodeJS server

wjfe/async-workers FAQ

Can I cancel a worker after it has started?+

No, cancellation is only possible before the worker starts due to lack of cross-origin isolation.

What if my site is cross-origin isolated?+

If cross-origin isolation is enabled, synchronization objects like SharedArrayBuffer can be used; otherwise they are unavailable.

Does this work in browsers that don’t support SharedArrayBuffer?+

Yes, but you can only cancel tasks before they start; pausing or mid-execution cancellation isn’t supported.

How do I use this library in NodeJS?+

Install a Worker polyfill such as the web-worker package, then import the async-workers module.

Summarized by DevHunt from wjsoftware.github.io · Sep 29, 2026. Details may change; check the official site.