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

ti-queue

v2.0.3

Published

Timed Invocation Queue

Downloads

21

Readme

Tiq - Timed Invocation Queue

A very lightweight (+-660 bytes) script to run functions in a certain order with certain delays.

Installation

bower install ti-queue

or

npm install --save ti-queue

or

yarn add ti-queue

The Tiq object

Tiq {
  queue: 'The execution queue'
  
  numberOfLoops: 'Number of loops to execute. Defaults to 1'
  timer: 'The current timeout ID'
  
  currentIndex: 'Current index'
  currentLoopIndex: 'Current loop index'
  
  sameMethodCounter: 'Counter of how many times a same method has been executed consecutively'
  executionCounter: 'Counter of how many methods were executed'
    
  lastCallback: 'The last callback that has been executed'
  beforeCallback: 'A callback method executed at the beginning of the queue'
  afterCallback: 'A callback method executed at the very end of the queue'
  
  playing: 'Is the queue running? true or false'
  hasExecutedBeforeCallback: 'Has the before callback been already executed? true or false'
}

Methods

All callbacks have this binded to the current Tiq object. The current Tiq instance is also passed as a parameter.

// Creates a new empty tiq
const tiq = new Tiq();

// Creates a new tiq with a specified queue
const tiq = new Tiq([[delay,function],[delay,function],...]);
// Adds a method to the queue with the specified delay
tiq.add(delay, function(tiqObject));
// Add 'numberOfRepetitions' entries of 'function' to the queue
tiq.repeat(numberOfRepetitions, delay, function(tiqObject));
// Method executed before the queue itself
tiq.before(function(tiqObject));
// Method executed after the queue ends
tiq.after(function(tiqObject));
// Executed after each queue item has been processed
tiq.each(delay, function(tiqObject));
// Set the number of loops
// numberOfLoops is optional. If not set, loops indefinitely.
// Default: 1 (no looping)
tiq.loop(numberOfLoops);
// Executed at the beginning of each loop iteration (if number of loops > 1)
tiq.beforeLoop(function(tiqObject));
// Executed at the end of each loop iteration (if number of loops > 1)
tiq.afterLoop(function(tiqObject));
// Runs the queue
tiq.run();
// Stops the queue
tiq.stop();
// Resets all of the queue's attributes (the queue array being an exception)
tiq.reset();

Methods can be chained

new Tiq().add(...,...).before(...).after(...).repeat(...,...,...).run();

Example

const Tiq = require('./dist/tiq.js');
const noop = () => 0;

new Tiq()
  .add(100, () => console.log('Print 1'))
  .add(100, () => console.log('Print 2'))
  .add(100, () => console.log('Print 3'))
  .add(100, () => console.log('Print 4'))
  .before(() => console.log('Print Before'))
  .after(function () {
    console.log(`Print After ${this.executionCounter} executions.`);
    new Tiq([
        [100, noop],
        [200, noop],
        [300, noop]
      ])
      .before(() => console.log('Starting loop\n'))
      .beforeLoop(o => console.log(`Begining of loop iteration ${o.currentLoopIndex}\n`))
      .afterLoop(o => console.log(`\nEnd of one loop iteration ${o.currentLoopIndex}\n`))
      .each(o => console.log(`Current Index: ${o.currentIndex}`))
      .loop(3)
      .after(function () {
        console.log(`\nOk, ended looping ${this.currentLoopIndex} times with a total of ${this.executionCounter} method executions.\n`);
        new Tiq()
          .before(() => console.log('\nLets end this.\n'))
          .repeat(10, 100, function () {
            console.log(`${this.currentIndex + 1} - Ending ${Array(this.sameMethodCounter + 2).join('.')}`);
          })
          .after(() => console.log('\nOk, done.'))
          .run();
      })
      .run();
  })
  .run();

Demo

To see the code above being executed just run node index.js.