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

angular-web-worker-resource

v1.0.0

Published

A reactive Angular resource that delegates work to Web Workers with automatic lifecycle management

Readme

Angular Web Worker Resource

A reactive Angular resource that bridges Angular's resource() API with Web Workers. Whenever the params signal changes, a fresh worker is spawned, the params are posted as a message, and the first response is resolved as the resource value. If params change while a worker is still running, the previous worker is terminated.

pnpm add angular-web-worker-resource

[!TIP] Zero dependencies, automatic worker lifecycle management, and full ResourceRef support.

Installation

pnpm add angular-web-worker-resource

Usage

Component

import { signal } from "@angular/core";
import { webWorkerResource } from "angular-web-worker-resource";

@Component({
	/* ... */
})
export class MyComponent {
	readonly input = signal(40);

	readonly result = webWorkerResource<number, number>({
		params: () => this.input(),
		worker: () => new Worker(new URL("./fibonacci.worker", import.meta.url)),
		defaultValue: 0,
	});
}
@if (result.isLoading()) {
<p>Computing...</p>
} @else if (result.error(); as error) {
<p>Error: {{ error }}</p>
} @else {
<p>Result: {{ result.value() }}</p>
}

Worker (with helper)

// fibonacci.worker.ts
import { onMessage } from "angular-web-worker-resource/worker";

function fibonacci(n: number): number {
	if (n <= 1) return n;
	return fibonacci(n - 1) + fibonacci(n - 2);
}

onMessage<number, number>((n) => fibonacci(n));

Worker (plain)

You can also write workers without the helper. Plain postMessage values are supported:

// fibonacci.worker.ts
addEventListener("message", ({ data }: MessageEvent<number>) => {
	const result = fibonacci(data);
	postMessage(result);
});

Without params

Workers that don't need input params run once immediately. Use .reload() to re-trigger:

readonly uuid = webWorkerResource<void, string>({
	worker: () => new Worker(new URL("./uuid.worker", import.meta.url)),
})

Worker Helper

The angular-web-worker-resource/worker entry point provides a typed onMessage helper for the worker side:

import { onMessage } from "angular-web-worker-resource/worker"

onMessage<TParams, TResult>(handler, transfer?)
  • Typed -- handler receives TParams and must return TResult | Promise<TResult>
  • Error handling -- exceptions are caught and reported back to the main thread, surfacing through resource().error()
  • Async support -- the handler can be async or return a Promise
  • Transfer support -- optional second argument derives Transferable[] from the result

API

webWorkerResource<TParams, TResult>(options)

Creates a reactive resource backed by a Web Worker.

Extends Angular's BaseResourceOptions, so all base options are supported.

Options

| Property | Type | Required | Description | | -------------- | ------------------------------------- | -------- | --------------------------------------------------------------------------- | | params | () => TParams \| undefined | No | Reactive computation producing params. Returning undefined keeps it idle. | | worker | () => Worker | Yes | Factory that creates a new Worker instance per invocation. | | transfer | (params: TParams) => Transferable[] | No | Derive transferable objects from params. | | defaultValue | TResult | No | Default value while loading or on error. | | equal | (a: TResult, b: TResult) => boolean | No | Custom equality function for the result value. | | injector | Injector | No | Overrides the injector used by the resource. |

[!NOTE] When params is omitted, the worker runs once immediately and won't rerun unless .reload() is called.

Returns

ResourceRef<TResult | undefined> (or ResourceRef<TResult> when defaultValue is provided).

onMessage<TParams, TResult>(handler, transfer?)

Registers a typed message handler in a Web Worker context. Import from angular-web-worker-resource/worker.

| Parameter | Type | Description | | ---------- | -------------------------------------------------- | --------------------------------------------- | | handler | (params: TParams) => TResult \| Promise<TResult> | Sync or async function that processes params. | | transfer | (result: TResult) => Transferable[] | Optional function to derive transferables. |

Error Handling

When using the onMessage helper, errors thrown by the handler are automatically caught and reported back to the main thread. The error surfaces through resource().error():

// worker
onMessage<string, string>((url) => {
	const res = await fetch(url)
	if (!res.ok) throw new Error(`HTTP ${res.status}`)
	return res.json()
})

// component template
@if (result.error(); as error) {
	<p>{{ error }}</p>
}

Workers without the helper can still report errors via the standard onerror event, but error messages are limited to what the browser provides.

Examples

For a full example project, see projects/app/.