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

synchronouz

v3.0.0

Published

Execute it all at once!

Downloads

14

Readme

Synchronouz

Execute it all at the once!

Synchronouz lets you execute several functions (as much as you want, actually!) at the same time, and emits a done event when everything finished.

Installation

To install, just type npm install synchronouz in a terminal.
To then use it, just do var sync = require("synchronouz"); in your application.

Usage

Sync (function|function[] functions...) : constructor

functions: function or Array.<function>; Rest. Any amount of functions or Arrays of functions to add.

Sync (or whatever you've called it) is a constructor, to which you can pass the same arguments as to Sync#add. You can also call it as normal function.

var one = function(cb) {...};
var two = function(cb) {
    cb("Hello, world!");
};
Sync(one, two);
    .exec();

Note: All functions should execute their callback (cb), otherwise the final callback will never be executed!

Sync#arguments (any[] arguments) - .

Alias: Sync#args, Sync#options
arguments: Array.<any>. The an array of arguments to apply to the functions.
return: Sync. For chaining.

The arguments will be .apply()ed to each function, with the callback as last argument. These are default arguments, so if you pass in arguments for Sync.add, these will not be used (for that particular function).
In the example, we pass in an array with one item in it, the string "Hello, world!". So the first argument to each function will be that string:

var one = function(message, cb) {
    console.log(message);
    cb();
}
var two = function(message, cb) {
    console.log(message);
    cb();
}

Sync()
    .options(["Hello, world!"]);
    .add(one);
    .add(two, ["hi"]);
    .exec();
    
//Will log:
// Hello, world!
// hi

Sync#args

Alias for Sync#arguments.

Sync#options

Alias for Sync#arguments.

Sync#add (function|function[] function, [any[] arguments]) - .

function: function or Array.<function>. A function, or array of functions, to add.
arguments: Array.<any>; Optional. An optional array of arguments to apply to the function(s). return: Sync. For chaining.

With Sync.add(), a function is added to the stack, but instead of using the arguments passed in with Sync#arguments, it will use the arguments passed to this method. For example:

var one = function(message, cb) {
    console.log("One: " + message);
    cb();
}
var two = function(anotherMessage, cb) {
    console.log("Two: " + anotherMessage);
    cb();
}
Sync(one)
    .options(["A message to One (and all other functions passed to Sync())!"]);
    .add(two, ["But this is a message to Two!"]);
    .exec();

Sync#execute ([function callback]) - .

callback: function; Optional. An optional callback for the Sync#"done" event.
return: Sync. For chaining.

Executes all the functions at once. You can optionally pass in a callback to be bound to the Sync#"done" event.

var one = function(args, cb) {
    console.log(args);
    cb();
}
var two = function(args, cb) {
    cb();
}
Sync(one, two)
    .options("Hello, world!")
    .exec(function(results) {
        console.log("Done!");
    });
    
//Will log:
// Hello, world!
// Done!

Sync#"done" (arguments[]|Error results)

results: the results of the functions.

When all the functions have run (i.e. all of them have executed their callback), the done event is emitted, with one argument: an array of Argument objects that were passed to the callbacks (in the order that the functions were added). One exception to this rule, is when one of the functions returned an Error: then, the done event is called immediately, with the Error it returned. The other results are ignored.

var one = function(cb) {
    cb();
}
var two = function(cb) {
    cb(new Error("404"));
}
Sync(one, two)
    .on("done", function(result) {
        console.log(result);
    })
    .exec();

##LICENSE

The MIT License (MIT)

Copyright (c) 2014 Tuur Dutoit

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.