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

workflow-for-js

v0.1.0

Published

Provides a workflow for JavaScript

Downloads

64

Readme

workflow-for-js

A JavaScript workflow engine with retry capabilities.

What is a workflow?

A workflow is a system for managing repetitive processes and tasks which occur in a particular order. They are the mechanism by which people and enterprises accomplish their work, whether manufacturing a product, providing a service, processing information or any other value-generating activity.

Install

To install workflow-for-js, you can use NPM:

npm install --save @kevboutin/workflow-for-js

Example

Please reference the example located in index.js.

Why?

This provides a way to handle retrying various tasks in a sequence. Using a workflow improves code readability and reliability. If you have multiple functions to run sequentially or perhaps the return from one function is a required parameter to the next function, a workflow is a perfect solution.

Usage

As you might have already seen from our example, using workflow is very simple and requires just few steps:

  1. Import Workflow.
import { Workflow } from "./workflow.js";
  1. Write your functions as usual. In our example, we have uploadImage, saveUser and sendVerificationEmail.
const saveUser = async ({ email, password, imageLink }) => {
    // ...
};
  1. Create your workflow inside of a try+catch block using Workflow.createWorkflow().
try {
    // Creating a workflow with a 4 retry limit.
    Workflow.createWorkflow(4, (workflow) => {
        // ...
    });
} catch (error) {
    console.error("Error in workflow.", error);
}
  1. Add each function as a workflow step using create().
workflow.create(async (image) => {
    // ...
});
  1. Optionally add a final workflow step using finally(). Note that finally() will not be retried. Use create() if retries are important.
workflow.finally(async ({ email }) => {
    // ...
});
  1. Run your workflow using run().
Workflow.run(image);

NOTE: Steps will be run in the order they are created.

Handling errors

But, what happens when there is an error?

When there is an error, the step will be retried until the retryLimit is reached. Once the limit is reached, the error will be thrown to your try+catch block for handling.

If you have a finally function, it will always be called prior to terminating the workflow despite errors in prior steps.

Publishing Releases

Use the following command to publish the various packages from this repository. Afterward, use GitHub to generate a new release based on the root package.json version.

npm publish