npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xan105/web-worker-thread

v0.1.0

Published

Execute Web Workers as promise without dedicated script file

Readme

About

Execute Web Workers as promise without dedicated script file.

📦 Scoped @xan105 packages are for my own personal use but feel free to use them.

Example

import { threadify } from "@xan105/web-worker-thread";

function fibonacci(n) {
  if (n <= 1n) return n;
  let a = 0n, b = 1n;
  for (let i = 2n; i <= n; i = i + 1n) {
    [a, b] = [b, a + b];
  }
  return b;
}

const n = await threadify(fibonacci)(100000n);
console.log(n);

This can be used as a "coroutine-like" with an AbortController:

import { threadify } from "@xan105/web-worker-thread";

function timer(i){
  return new Promise((resolve) => setTimeout(() => resolve(), i));
}

const controller = new AbortController();
const { signal } = controller;
threadify(timer, { signal })(500).catch(console.error);
setTimeout(() => controller.abort(), 100);

Install

npm i @xan105/web-worker-thread

💡 The bundled library and its minified version can be found in the ./dist folder.

Via importmap

Create an importmap and add it to your html:

  <script type="importmap">
  {
    "imports": {
      "@xan105/web-worker-thread": "./path/to/node_modules/@xan105/web-worker-thread/dist/thread.min.js"
    }
  }
  </script>
  <script src="./index.js" type="module"></script>
  </body>
</html>

index.js:

  import { threadify } from "@xan105/web-worker-thread"
  await threadify(foo)("bar");

API

⚠️ This module is only available as an ECMAScript module (ESM) and is intended for the browser.

Named export

threadify(fn: function | Promise, option?: object): (...args: unknown[]) => Promise<unknown>

Spawn a web worker and run the given function (sync or async) inside the web worker.

ℹ️ Usage is similar to node:util/promisify syntax:

import { threadify } from "@xan105/web-worker-thread";

function double(i){
  return i * 2;
}

const i = await threadify(double)(2);
console.log(i); //4

⚙️ Options

{
  timeout?: number,
  importScripts?: string[],
  signal?: AbortSignal
}
  • timeout?: number (0)

Optional timeout (in ms) to cancel the web worker if it takes too much time.

  • importScripts?: string[] (none)

Optional array of script path(s) to import into the web worker's scope. See importScripts for more details.

  • signal?: AbortSignal (none)

Optional Abort controller signal to abort the web worker. See AbortController for more details.

↩️ Return

Returns a function that, when called with any arguments, executes the original function in a separate thread (web worker) and returns a Promise that:

  • ✔️ resolves to the original function's result
  • ❌ or rejects on error