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

@serve-tools/ponyfill-prioritized-task-scheduling

v0.1.3

Published

Implements the Prioritized Task Scheduling API without global mutation

Readme

@serve-tools/ponyfill-prioritized-task-scheduling

Queue work by urgency and await its result, with cancellation and reprioritization when requirements change. The @serve-tools/ponyfill-prioritized-task-scheduling package implements the Prioritized Task Scheduling API without modifying the global environment. It provides a module-scoped scheduler, task controls, dynamic priorities, abortable delays, and prioritized continuations in windows and workers.

import { scheduler } from "@serve-tools/ponyfill-prioritized-task-scheduling";

const title = await scheduler.postTask(() => "Ready to edit", { priority: "user-blocking" });
console.log(title); // “Ready to edit”, after the scheduled callback runs.

Install

npm install @serve-tools/ponyfill-prioritized-task-scheduling

Import from a CDN

import * as ponyfillPrioritizedTaskScheduling from "https://esm.run/@serve-tools/ponyfill-prioritized-task-scheduling";

Control task priority and cancellation

import { scheduler, TaskController } from "@serve-tools/ponyfill-prioritized-task-scheduling";

const controller = new TaskController({ priority: "background" });
const task = scheduler.postTask(() => prepareOffscreenContent(), { signal: controller.signal });

controller.setPriority("user-visible");

await task;

TaskController extends AbortController. Its TaskSignal remains usable by APIs that accept an AbortSignal, dispatches prioritychange events, and reprioritizes all queued scheduler work associated with the signal. An explicit postTask priority overrides the signal's priority and remains immutable.

Yield between chunks

await scheduler.postTask(
	async () => {
		processFirstChunk();
		await scheduler.yield();
		processSecondChunk();
	},
	{ priority: "user-blocking" },
);

Continuations run ahead of newly posted work at the same priority. A yield() called directly before the originating callback returns inherits that callback's priority and abort signal. JavaScript cannot preserve the browser's internal scheduling state through arbitrary promise and microtask continuations, so a yield() called after another asynchronous suspension uses the default user-visible fallback priority.

Public API

  • scheduler.postTask(callback, options): schedules one callback and resolves with its result.
  • scheduler.yield(): yields to a separately scheduled continuation.
  • Scheduler: the non-constructible interface object for scheduler instances.
  • TaskController: aborts and reprioritizes tasks sharing its signal.
  • TaskSignal: extends AbortSignal with priority, prioritychange, and TaskSignal.any().
  • TaskPriorityChangeEvent: exposes the previous priority.
  • Scheduling options, callbacks, priorities, controls, signals, and event contracts are exported as TypeScript types.

Scheduling behavior

Each posted callback or continuation runs in a separate host task, preserving a microtask checkpoint and an opportunity for the host to process unrelated work between callbacks. Tasks are selected by effective priority and then global enqueue order. Continuations rank immediately above newly posted tasks at the same semantic priority.

In windows, user-blocking and user-visible work uses a MessageChannel. background work uses @serve-tools/ponyfill-request-idle-callback with a ten-second timeout for hidden-document forward progress. In workers, all priorities use a MessageChannel, so priority ordering is local to this scheduler.

The fallback cannot communicate priority to the browser or coordinate with tasks from other sources. user-blocking and user-visible therefore differ in their ordering within this package, not in browser-controlled event-loop priority.

Ponyfill boundary

The exported scheduler and task controls always use this package's implementation, even when native globals exist. No import installs or replaces globalThis.scheduler, globalThis.TaskController, globalThis.TaskSignal, or globalThis.TaskPriorityChangeEvent. Use @serve-tools/polyfill-prioritized-task-scheduling when native identity or global installation is required.

Compatibility

The package requires modern AbortController, AbortSignal, DOMException, EventTarget, MessageChannel, promises, and timers. Window background scheduling additionally requires document, performance, and requestAnimationFrame through the idle-callback ponyfill.

Agent Skill

This package includes skills/serve-tools-ponyfill-prioritized-task-scheduling/SKILL.md with version-aligned usage guidance for compatible coding agents. Activation is explicit; installing the package does not automatically trust or enable it.

Development

npm run typecheck --workspace @serve-tools/ponyfill-prioritized-task-scheduling
npm test --workspace @serve-tools/ponyfill-prioritized-task-scheduling
npm run build --workspace @serve-tools/ponyfill-prioritized-task-scheduling

License

MIT-0