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

l8r

v1.0.0

Published

queue multiple functions and run later

Downloads

6

Readme

l8r NPM version Build Status Dependency Status

queue multiple functions and run later

Niceties

  • widely compatible and small codebase

Caveats

  • there is no built in mechanism to receive return values; use callbacks or promises
  • any unhandled exception will stop subsequent function calls

Installation

$ npm install --save l8r

Example

'use strict';

// let's queue socket listeners before we have a connection

var L8r = require('l8r');

var httpServer = require('http').createServer().listen(3000);
var io = require('socket.io')(httpServer);
var ioClient = require('socket.io-client')('http://localhost:3000');

// ...

// queue client-side listeners
var clientListeners = new L8r();

(function () {
  var self = {
    smile: '=)'
  };

  clientListeners.add(function (socket) {
    var smile = this.smile || self.smile;

    socket.on('smile', function (gesture) {
      var smiley = gesture || smile;
      console.log(smiley);

      if (smile === '=)') {
        socket.emit('wink');
      }
    });

    socket.on('smirk', function (gesture) {
      if (gesture === ';D' && smile === ':-)') {
        console.log(gesture);
        httpServer.close();
        ioClient.close();
      }
    });
  });
})();

// ...

// queue server-side listeners
var serverListeners = new L8r();

(function () {
  serverListeners.add(function (socket) {
    socket.once('wink', function () {
      socket.emit('smirk', ';D');
    });
  });
})();

// ...

// now that it's later, add listeners
serverListeners.run(ioClient);

// ...

io.on('connection', function (socket) {
  // now we that we have the connected socket, 
  // we can add listeners
  clientListeners.run(socket);

  // if you want to pass context to all the functions,
  // use "apply()" instead of "run()"
  clientListeners.apply({
    smile: ':-)'
  }, [socket]);

  ioClient.emit('smile');
  // => =)
  // => :-)
  // => ;D
});

API

add(fn)

  • fn

    Required Type Function

    A function to be queued for calling later.

run([arguments])

Run all the functions added to the queue, passing in any arguments
  • arguments

    Type: Any

    Parameters to pass into each function

apply(context, [parameters])

Run all the functions added to the queue, with context, 
applying an array of parameters (if provided)
  • context

    Required Type: Object

  • parameters

    Type: Array

queue

The queue of functions to be called later

q

An alias for `queue`

License

ISC © Buster Collings