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

silly-barrier

v1.0.0

Published

Routine to synchronize several asynchronous functions that invoke callbacks.

Downloads

26

Readme

silly-barrier

JS module presenting routine to synchronize several asynchronous functions that invoke callbacks.

Version

Current module version is 1.0.0, and development assumed finished. The version will not change if there are no bug reports.

License

silly-barrier is licensed under BSD 3-clause "Revised" License. See license for details.

Usage

Install

Just run command npm install silly-barrier to have this module installed for your project. See usage of npm tool for details.

Dependencies

Current version of silly-barrier has no dependencies.

Test

To test module just run command nodejs ./test.js from the console in the folder where module is placed. You should see the output like that:

Routine #0 output
Callback #0 output
...
Routine #4 output
Callback #4 output
Invoking final callback...
Final callback invoked, output has 12 lines
1) Routine #0 output
2) Callback #0 output
...
9) Routine #4 output
10) Callback #4 output
11) Invoking final callback...
12) Final callback invoked, output has 12 lines

Run

For using silly-barrier in a code one need to form an array of so-called routines. Each routine should contain at least field func which value should be a function that will be invoked as some asynchronous routine.

Routine can also contain optional field args - array of arguments to pass to the function while invoking including callback for that routine. If no arguments are specified, no callback can be called therefore.

There is also yet another optinal field cbkey which can specify index of a callback function in the arguments array. If no field cbkey is cpecified for current routine, the last function in the arguments array will be assumed as callback (even if it is not the last argument of the entire array).

Example of routines array:

var routines = [
	{ 
		func: ( arg1, arg2, callbackfn ) => { 
			var temp = arg1 + arg2;
			callbackfn( temp );
		},
		args: [ 1, 2, alert ]
	},
	{ 
		func: ( arg1, callbackfn, somefunc ) => {
			var temp = somefunc( arg1 );
			callbackfn( temp );
		},
		args: [ 0.5, console.log, Math.sin ],
		cbkey: 1 
	},
	{
		func: () => { console.log( 'Routine without arguments and callback.' ) }
	}
];

After creating of described array, one should call imported barier function with next parameters:

  • routines - array described above,
  • callback - description of the routine to be invoked in the very final, after completing of every routine from the first parameter array.

callback should contain field func specifying the function to call at the very end of all work. It also may contain an optional array args of arguments to pass to the function while invoking.

Example of function barrier calling:

require('silly-barrier').barrier( routines, { func: alert, args: [ 'Finished!' ] } );

The full working example of module usage one can find in test.js.