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

promised-runnable

v0.2.3

Published

Configurable object for performing operation.

Downloads

18

Readme

Build Status NPM Version Dependency Status

promised-runnable

Configurable object for performing operation.

The source code is available on GitHub where you can also find our issue tracker.

Installation

Run the command below to install the package.

$ npm install --save promised-runnable

Getting Started

To make the code clean, the examples are written in TypeScript.

Let's start with the simplest Runnable example.

import { Runnable } from "promised-runnable";

const runnable = new Runnable({
  action: () => "Done!", // Executable code block.
});

runnable.perform().then(() => {
  console.log(err); // -> "Done!"
}).catch((err) => {
  console.log(err);
});

Runnable can delay the execution.

const runnable = new Runnable({
  action: () => "Done!",
  delay: 1000, // delay execution for 1s
});

Runnable can retry the execution if it fails.

const runnable = new Runnable({
  action: () => "Done!",
  retries: 5, // retry 5x before failing
  retryDelay: 1000, // delay the execution between retries
});

Runnable can handle timeouts.

const runnable = new Runnable({
  action: () => "Done!",
  timeout: 5000, // throws the RunnableTimeoutError if the execution takes more then 5s
});

Runnable can schedule the execution at a different time in the future. To give this feature more sence, let's define a new runnable object which can execute up to 1 command per second.

/** Schedule */
const Redis = require("ioredis");
const { Quota } = require("ioredis-quota");
const redis = new Redis();
const quota = new Quota({ redis });
const schedule = () => quota.schedule({
  key: 'test-done',
  unit: 'second',
  limit: 1
});

/** Runnable */
const { Runnable } = require(".");
(async function() {
  const runnable = new Runnable({
    action: () => "Done!",
    schedule, // limit execution to 1 per second
  });
  for (let i = 0; i < 10; i++) {
    runnable.perform().then((d) => {
      console.log(d); // -> "Done!"
    }).catch((e) => {
      console.log(e);
    });
  }
})();

Runnable execution can be canceled.

runnable.cancel();

License (MIT)

Copyright (c) 2016+ Kristijan Sedlak <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated modelation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.