🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

simple-queuer

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-queuer

A simple queueing mechanism

latest
Source
npmnpm
Version
2.1.4
Version published
Maintainers
1
Created
Source

queuer

Introduction

This is a simple queueing mechanism. It uses interval to check remaining items in the queue. Uses es2015 syntaxes.

Installation

$ npm install --save simple-queuer;

Usage: basic

// import the class
import Queuer from 'simple-queuer';

// instantiate
var queuer = new Queuer(10); // the default value is 10.

// add tasks. this will automatically start the queue.
queuer.push(
	function(next){
		setTimeout(()=>{next()}, 1000);
	}
);

Usage: async with promise

"use strict";

// import the class
import Queuer from 'simple-queuer';

// instantiate
var queuer = new Queuer(10); // the default value is 10.

function getRandomTimer(){
	return new Promise( (resolve, reject) => {
		let timer = (next) => {
			setTimeout(()=>{
				console.log('timer '+i+' done!')
				resolve(i);
			}, Math.random()*1000);
		}
		queuer.push(timer);
	});
}

// let's create 100 random timers
var promises = [];
for(var i=0; i< 100; i++){
	promises.push(getRandomTimer());
}
Promise
	.all(promises)
	.then((results) => {
		console.log('all timers done!');
	})
;

Keywords

javascript

FAQs

Package last updated on 26 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts