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

task_throttler

v0.1.5

Published

Allows you to queue up functions as tasks and set what rate of speed they fire off. Can be a single interval or it can repeat.

Downloads

3

Readme

Task Throttler

Task Throttler is a module that is designed to allow you to queue up functions and have them start/stop and run at whatever rate over time that you specify. I had to access an API that could only have requests made to it 30 times in a minute so I made this simple module to allow me to create the task with the ability to start and stop it anytime and best of all specify the interval not only in milliseconds but also in plaintext. Made it in about 30 minutes so its kind of dirty and not the most efficient for long running scripts, but if you are making a quick importer or exporter that needs to read/write and api, it should work fine. Keep an eye out for the git, it would be cool to make this more efficient.

Version

0.1.2

Tech

Task Throttler only uses nodes built in timer functions. It is not meant to be super precise, just simple and effective.

Installation

npm install task_throttler

Usage

This example is just passing in an anonymous function as a callback, but you can create any function and pass it to the queue.

//This will create a task that starts automatically and will execute every second.
var Throttler = require('task_throttler'),
    throttle = new Throttle,
    someArray = ["item1", "item2", "item3", "item4", "item5", "item6"];
    
throttle.queue("testTask", 1000, {
	autoStart : true
}, function(task) {
    //Stuff below here
	if (queue.length) {
		console.log(queue);
		someArray.shift();
	} else {
		throttle.stop(task.name);
	}
	//stuff above here
});

Methods

queue()

Throttler.queue(name, interval, options, callback);

This creates the task. When adding a task to the queue it just means you have made one that can be used. It can be autostarted or started manually and when stopped it is not automatically deleted, it will remain in the task object to be turned on again later if you wish.

Arguments

####-name (string) - Required

     Name of the task

####-interval (string | integer) - Required

     Time between each cycle. If you pass it an integer, it will be time in milliseconds. If you pass it a string, it must be in the following format: " [number of cycles]/[unit of time measurement] ", ie: "5/minute" = 5 times a minute.

####-options (object) - Optional

     Options to be passed to your task;

     autoStart: (true | false) - Automatically starts the script. Default: false

     runOnce: (true | false) - Script will automatically stop after one cycle, it uses setTimeout. Default: false

     killOnStop: (true | false) - Automatically removes task from queue when it is stopped. Default: false

     cycles: (integer) - Number of times you want the task to run before stopping. Default: 0 (forever)

####-callback (function) - Required

     Your actual task. Can be an anonymous function or a named one.


start()

Throttler.start(name);

Start a task, name is the actualy name you gave it when using .queue()


stop()

Throttler.stop(name);

Stop a task, name is the actualy name you gave it when using .queue()


kill()

Throttler.stop(name);

Kill a task, name is the actualy name you gave it when using .queue(). Once killed, a task cannot be restarted and would need to be requeued.


running()

Throttler.running();

This is more of a utility function. It will return and object that contains all of the running tasks. Could use it to iterate through and stop or kill all etc. In the source, there actually are some arguments, but they are used for managing the running object.


There are a few more utility functions, but I didn't intend on ever using them directly, but they are there if you want to take a look and mess with them. License

MIT

Free to use for whatever