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 🙏

© 2024 – Pkg Stats / Ryan Hefner

scheduler-polyfill

v1.3.0

Published

Polyfill of self.scheduler API

Downloads

17,852

Readme

Scheduler Polyfill

This is a polyfill for the Prioritized Task Scheduling API. Documentation can be found on MDN.

The polyfill includes implementations of Scheduler, exposed through self.scheduler, as well as TaskController and TaskPriorityChangeEvent classes.

scheduler.postTask()

The implementation uses a combination of setTimeout, MessageChannel, and requestIdleCallback to implement task scheduling, falling back to setTimeout when other APIs are not available.

The polyfill, like the native implementation, runs scheduler tasks in descending priority order ('user-blocking' > 'user-visible' > 'background'). But there are some differences in the relative order of non-scheduler tasks:

  • "background" tasks are scheduled using requestIdleCallback on browsers that support it, which provides similar scheduling as scheduler. For browsers that don't support it, these tasks do not have low/idle event loop priority.

  • "user-blocking" tasks have the same event loop scheduling prioritization as "user-visible" (similar to setTimeout()), meaning these tasks do not have a higher event loop priority.

scheduler.yield()

The polyfill does not support priority or signal inheritance, so all continuations are scheduled with "user-visible" continuation priority. The scheduling behavior of this depends on whether the browser supports scheduler.postTask() (i.e. older Chrome versions):

  • For browsers that support scheduler.postTask(), scheduler.yield() is polyfilled with "user-blocking" scheduler.postTask() tasks. This means they typically have a higher event loop priority than other tasks (consistent with yield()), but they can be interleaved with other "user-blocking" tasks.

  • On browsers that don't support scheduler.postTask(), the same event loop prioritization as the postTask() polyfill applies (see above), but continuations run between "user-blocking" and "user-visible" tasks.

Requirements

A browser that supports ES6 is required for this polyfill.

Usage

Include via npm and a bundler

npm install scheduler-polyfill

Import to populate the task-scheduling global variables, if not already available in the executing browser:

import 'scheduler-polyfill';

Include via unpkg

<script src="https://unpkg.com/scheduler-polyfill"></script>

Building from source

git clone https://github.com/GoogleChromeLabs/scheduler-polyfill
cd scheduler-polyfill
npm i
npm test        # Tests should pass
npm run build   # Outputs minified polyfill to dist/
<script src="/path_to_polyfill/scheduler-polyfill.js"></script>

License

Apache 2.0