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

@downpourdigital/scheduler

v1.0.0

Published

A simple render task scheduler

Downloads

52

Readme

@downpourdigital/scheduler

npm bundle size npm dependencies

A simple render task scheduler.

Installation

yarn add @downpourdigital/scheduler
npm i --save @downpourdigital/scheduler

Usage

import scheduler, {
	read,
	update,
	render,
	postRender,
	loop,
	defer,
} from "@downpourdigital/scheduler";

Each frame is divided intro several phases:

  1. read
  2. update
  3. render
  4. postRender

They should be self-descriptive. Each phase is executed after the other.

read(), update(), render() and postRender() cause the supplied function to be executed at the next possible opportunity.

Additionally, defer() allows you to postpone an expensive action. A maximum of one action is executed per frame. The deferred queue can be paused and resumed with scheduler.pauseDeferred() and scheduler.resumeDeferred() respectively. The execution order can be altered by giving the task a priority. (The higher, the earlier the task will be executed.) The default priority is 0.

loop() lets you schedule a function for execution on every frame.

All helpers return a function, that, when executed, cancels the task.

Start

To start the scheduler, call scheduler.start() once your application is ready. It can be paused again with scheduler.pause(). Execution will be automatically paused if the tab/window is out of view.

Similarly, scheduler.resumeDeferred() needs to be called to start executing deferred tasks. Ideally this should happen inside a call to window.requestIdleCallback.

Example

import scheduler, {
	read,
	update,
	render,
	postRender,
	loop,
	defer,
} from '@downpourdigital/scheduler';


scheduler.start();
window.requestIdleCallback( () => scheduler.resumeDeferred() );


// update something once
update( ( delta, time ) => someDomNode.style.opacity = 1 );

const cancel = loop( ( delta, time ) => ([
	update( () => {
		someDomNode.style.opacity = Math.sin( time ) * .5 + .5;
	}),
	postRender( () => {
		// calculate something for next frame
		// e.g. advance a physics sim
	}),
]) );

// calling cancel() will cancel the loop as well as all
// associated tasks that have not yet been executed

setTimeout( () => {
	// cancel the loop after 1 second
	cancel();
}, 1000 );

defer( () => {
	// something expensive
	// like uploading a texture to the GPU
}, 1 ); // optional priority

To do

  • better docs
  • testing

License

© 2020 DOWNPOUR DIGITAL, licensed under BSD-4-Clause