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

async-timed-cargo

v0.0.3

Published

An lib to periodically flush a collection with a limited size based on async.cargo

Downloads

2,398

Readme

Async Timed Cargo

Build Status

NPM

async.cargo based task execution.

Differences from async.cargo

Async.cargo:

  • Payload number is used as a limit to the message, but most times the callback is called with a fewer number of items
  • It tries to process tasks as soon as possible when they are pushed, which is bad if used to control batch messages processing, as it will result in more calls with fewer items

async-timed-cargo

  • Adds a timer concept to the task execution
  • Payload tries to be respected, if number of messages received is less than payload it does not do anything until timer is triggered or more messages are received, whatever comes first
  • It is better for message batch process as it waits until the queue is full

Install

add async-timed-cargo to you package.json

Example


var asyncTimedCargo = require('async-timed-cargo');

var cargo = asyncTimedCargo(function(tasks, callback) {

  // the tasks array will be [1, 2, 3]
  // this will be called after 1000ms, as number of items (3) is smaller than payload (10)
  callback('err', 'arg');

}, 10, 1000);

asyncTimedCargo.push(1);
asyncTimedCargo.push(2);
asyncTimedCargo.push(3, function(err, arg) {
  // err will be 'err'
  // arg will be 'arg'
});

Also, check the example app for a working example on how to use the middleware

Usage

async-timed-cargo(worker, [[payload], timeout])

Arguments

  • worker(tasks, callback) - An asynchronous function for processing an array of queued tasks, which must call its callback(err, arg) argument when finished, with an optional err and arg argument.
  • payload - An optional integer for determining how many tasks should be processed per round; if omitted, the default is unlimited and only timer will be considered
  • timeout - An optional integer for determining the interval (in ms) to be used to flush data each round; if omitted, the default is 1000ms

Cargo objects

The cargo object returned by this function has the following properties and methods:

  • length() - A function returning the number of items waiting to be processed.
  • push(task, [callback]) - Adds task to the queue. The callback is called once the worker has finished processing the task. Instead of a single task, an array of tasks can be submitted. The respective callback is used for every task in the list.

Test

$ npm install
$ npm test