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

qsync

v0.0.8

Published

[Under development]

Downloads

4

Readme

qsync

Quick sync is a two API solution to synchronize asynchronous function calls. It helps to implement common control flow scenarios easily.

Installation

This module is originally written for nodejs. Though it's planned to port into other areas in future.

$ npm install qsync

##Quick Example

// Synchronize with states
qsync.serial([10, 20, 30], {
    idle: function (input, callback) { ... },
    active: function (result, callback) { ... },
    close: function (result, callback) { ... }
},
function (error, results) {
});

// Classic synchronization
qsync.serial([10, 20, 30], [
    function (input, callback) { ... },
    function (result, callback) { ... }
], callback);

// Process inputs in parallel
qsync.parallel([10, 20, 30], [
    function(input, callback){ ... },
    function(result, callback){ ... }
],
function (error, results) {
});

##Contents

Arguments

  • input - Optional
  • no input If no input is given, all tasks will be run only once. Also input argument of first task will be null. In parallel API, all tasks will be running concurrently.
qsync.serial([
   function (input, callback) {...}
]);
  • single input Given data will be passed as the input argument of first task. It can be a number, string or a json object. All tasks will be run only once. In parallel API, all tasks will be running concurrently.
qsync.serial(15, [
   function (input, callback) {...}
]);
  • array input In case of an array input, each array element will be passed as the input argument of first task. If array has n number of elements, tasks will be run n times each corresponds to a respective data in array. In both API, a group of tasks are created to process each input. The groups can run either sequentially (in serial API) or concurrently (in parallel API). Though the tasks inside a group will be running in serial by default in both the APIs. In parallel API, each array element will be processed in parallel. Note that the tasks inside a group are still running serially and this default behavior can be modified by overriding flow control middleware. This default behavior is different in no input and in single input scenario. In below example, a group of task1 and task2 for processing input 10 will be created and running in serial. another group of task1 and task2 for processing input 15 will also be created and running in serial and a third task group for processing 20 will also be running similarly. But in parallel API, all these groups will be running in parallel so that all inputs will be processed in parallel. But inside any of the three group, task1 and task2 will be running in serial.
qsync.serial([10, 15, 20], {
   task1: function (input, callback) {...},
   task2: function (result, callback) {...}
});
  • variadic input This input is same as single input. All the inputs will be passed as variadic arguments of first task. In below example, 3, 5 and 11 will be passed to first task as its 1st, 2nd and 3rd argument respectively. callback will be its 4th argument.
qsync.serial(3, 5, 11, [
   function (input, callback) {...}
]);
  • tasks
  • single task Only one function will be given as a task with following syntax.
function (input1, input2, ..., callback) {}

input1, input2, etc are the input argument provided to the API or the input passed via callback of previously called task.

qsync.serial([10, 15, 20], function (input, callback) {...});
  • json tasks Instead of giving a single task, it's possible to give a number of labeled task so that the input can be processed as a state machine.
{
   label1: function (input1, input2, ..., callback) {},
   label2: function (input1, input2, ..., callback) {},
   :
   labelN: function (input1, input2, ..., callback) {}
}

In above syntax, all functions should have the same syntax as explained in single task.

qsync.serial([10, 15, 20], {
   idle: function (input, callback) {...},
   active: function (result, callback) {...},
   close: function (result, callback) { ... }
});
  • array of tasks An array of functions can also be given as tasks if labels are not significant.
[
   function (input1, input2, ..., callback) {},
   function (input1, input2, ..., callback) {},
   :
   function (input1, input2, ..., callback) {}
]

In above syntax, all functions should have the same syntax as explained in single task.

qsync.serial([10, 15, 20], [
   function (input, callback) {...},
   function (result, callback) {...}
]);
  • callback(error, result) - An optional callback which is called when all inputs are processed or an error occurs. By default the result argument will be the result returned by last task. However it's possible to change this behavior by overriding middleware as explained in section Storage. If last task didn't pass a result, only error argument will be passed to this callback.

Copyright (c) 2015 Fazil Vadakkumpadath

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.