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

sequencer.js

v4.2.2

Published

A simple but powerful and extensible JavaScript task sequencer

Downloads

25

Readme

sequencer.js

A simple but powerful and extensible JavaScript task sequencer.

Installation

Using NPM

npm install --save sequencer.js

Usage

// Create a handle and release it after some time has passed.
// The sequence will block at `doWaitForHandle(blockUntilLaterHandle)` until the handle is released.
var blockUntilLaterHandle = new Handle();
setTimeout(blockUntilLaterHandle.release, 10000);

var sequencer = new Sequencer();

// Enqueue a simple synchronous action
sequencer.do(() => log("1st instantly"));

// Waits for one second then performs an action after the delay has elapsed.
// This also demonstrates "do" task chaining.
sequencer.doWait(1000).do(() => log("2nd after 1 second"));

// Performs an action and waits until release() is called
sequencer.doWaitForRelease(release => setTimeout(release, 3000));

sequencer.do(() => log("3rd after waiting for a release() call"));

// Block until the handle is released
sequencer.doWaitForHandle(blockUntilLaterHandle);

sequencer.do(() => log("4th after waiting for a manually-created handle to be released"));

// Performs an action and waits until release() is called a certain number of times.
// The sequencer proceeds after 5 seconds (when two releases have been performed).
sequencer.doWaitForReleases(2, release => {
  setTimeout(release, 5000);
  setTimeout(release, 3000);
});

sequencer.do(() => log("5th after waiting for two release() calls"));

// Wait for a promise to be fulfilled.
// You can optionally obtain the promise's value and/or rejection reason.
var url = "https://cors-test.appspot.com/test";
sequencer.doWaitForPromise(fetch(url), response => log(`(Promise Resolved : HTTP ${response.status} from ${url})`));

sequencer.do(() => log("6th after waiting for a promise to be resolved"));

sequencer.doSequence(s => {
  s.doWait(1000);
  s.do(() => log(`> Subsequence : First`));
  s.doWait(1000);
  s.do(() => log(`> Subsequence : Second`));
  s.doWait(1000);
  s.do(() => log(`> Subsequence : Third`));
  s.doWait(1000);
});

sequencer.do(() => log("7th after waiting for a subsequence to complete"));

Creating an Extension

An external sequencer.js extension looks like this:

var DoSomethingTask = function (someValue) {
    this.perform = function (handle) {
        // Do something, synchronously or asynchronously
        setTimeout(() => {
          console.log("Task performed after 2 seconds with value " + someValue);
          handle.release(); // Then release the handle to indicate that the task is complete
        }, 2000);
    };
};

Sequencer.prototype.doSomething = function (someValue) {
    this.push(new DoSomethingTask(someValue));
    return this;
}

Take a look at core extensions in the sequencer.js source for concrete examples. The way the extensions are installed is slightly different from external extensions, but they still serve as appropriate examples.