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

workshy

v1.0.4

Published

A small (354B) lazy function scheduler for a butter smooth main thread

Downloads

20

Readme

workshy Build Status Version

A small (376B) lazy function scheduler for a butter smooth main thread

Workshy is a throttle utility that rate limit, queue, and distribute function executions over time to prevent the main thread from becoming unresponsive.

Unlike a standard throttle function, and to ensure non-blocking rendering and responsive UIs, workshy break up functions into smaller chunks executed over time if necessary.

This module is available in three formats:

  • ES Module: dist/workshy.mjs
  • CommonJS: dist/workshy.js
  • UMD: dist/workshy.min.js

Install

$ npm install --save workshy

The script can also be directly included from unpkg.com:

<script src="https://unpkg.com/workshy"></script>

Usage

import workshy from 'workshy';

// dummy function doing heavy work
const greet = () => 'hello world';

// queue and call function
workshy(greet)();
// => 'hello world'

// tasks are only called once, but
// multiple calls increases priority
const a = workshy(x => console.log(`A: ${x}`));
const b = workshy(x => console.log(`B: ${x}`));
b(1);
a(1);
a(2);
// => A: 2
// => B: 1

// manually define priority
const func = workshy(greet, {priority: 2});

// force it to be called immediately
const func = workshy(greet, {force: true});

// workshy distribute the work over time to
// make sure the main thread runs butter smooth
for (let i = 0; i < 5000; i++) {
  workshy(greet)(); // => this won't block UI
}

API

workshy(task, [options])

Returns: function

task

Type: function

Accepts any function a returns a function (a function that wraps your original function). Call returned function to queue task.

The returned function will execute your function with the latest arguments provided to it as soon as possible based on queue length and prioroty.

Important: Task are only called once. Calling the same task multiple times increases its priority.

options.priority

Type: Number Default: 0

Tasks are sorted by priority. Functions with high priority are called first.

Important: Priority also increase if a task is called multiple times.

workshy(() => console.log('Hello World'), {force: false, priority: 2});
//=> 'Hello World'

options.force

Type: Boolean Default: false

workshy(() => console.log('Hello World'), {force: false, priority: 2});
//=> 'Hello World'

Inspiration

This is inspired by the talk The Virtue of Laziness: Leveraging Incrementality for Faster Web UI

License

MIT © Terkel Gjervig