New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

queue.ls

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue.ls

Promise based task queue with concurrency limit

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

queue.ls

Promise based task queue with concurrency limit.

NPM version build status

Example

const https = require('https');
const url = require('url');
const queue = require('queue.ls');

q = queue({ concurrency: 3 });

const tasks = [];
for (let i = 1; i <= 20; i++) {
  tasks.push(q.add(fetchPage(i)));
}
Promise.all(tasks).then(pages =>
  console.log(pages.reduce((a, b) => a.concat(b)))
);

function fetchPage(i) {
  const options = url.parse(
    `https://api.github.com/repos/jquery/jquery/commits?page=${i}`);
  options.headers = { 'User-Agent': 'Awesome-Octocat-App' };
  return function() {
    return new Promise(resolve => {
      https.get(options, res => {
        const buffer = [];
        res.on('data', chunk => buffer.push(chunk));
        res.on('end', () => resolve(JSON.parse(buffer.join(''))));
      });
    });
  };
};

Example

require! https
require! url
queue = require \queue.ls

q = queue concurrency: 3
fetch-page = (i) ->
  options = url.parse \
  "https://api.github.com/repos/jquery/jquery/commits?page=#i"
  options <<< headers: 'User-Agent': \Awesome-Octocat-App
  ->
    new Promise (resolve) ->
      res <- https.get options
      buffer = []
      res.on \data buffer~push
      <- res.on \end
      resolve JSON.parse buffer.join ''

tasks = for i from 1 to 20
  q.add fetch-page i

Promise.all tasks .then (pages) ->
  console.log pages.reduce (++)

Install

npm i --save queue.ls

queue([options])

  • options <Integer> | <Object>
    • concurrency: Maximum number of tasks should run concurrently, defaults to 1.
    • promise: your Promise class, defaults to global Promise.

Returns a queue object.

If options is an integer, then it specifies the concurrency.

queue.add(task[, callback])

  • task <Function>
  • callback <Function>

Returns a promise, resolves to the result of task.

If task does not return a Promise, the result will be wrapped by Promise.resolve.

When the result of task resolved , optional callback will be called with it.

queue.push(task[, callback])

Alias for queue.add(task, callback)

Keywords

queue

FAQs

Package last updated on 15 Aug 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