pacu

1.6.2 • Public • Published

pacu

It is a tool to solve the problem of resolving serise promise functions with parameter continuously. And there is not a solution but only resolving parallelly.

NPM

Install

$ npm install --save pacu

Usage

Initializing pacu

var pacu = require("pacu")

Important

To accomplish running promise function one after one is difficult, because the object format of promise function and promise function with parameter are different in js ( issue of anonymous function with parameters ). So that handling this issue needed to push promise function(not a promise) to an array list, which will be resolved:

 
    var genPromist = function(para) {
        return new Promise(function(resolve, reject) {
            setTimeout(function() {
                console.log('para: ', para)
                resolve(para * para)
            }, 1000)
        })
    };
 
    var promisesList = [];
 
    promisesList.push(function(){
        return genPromist(i)
    });
 
## Usage
//processing promiseList by series
 
var pacu = require("pacu")
 
pacu.series(promisesList).then(function(result) {
    console.log("Result series: ", result)
},function(err){
    console.log("Error series: ", result)
});
 
## Usage closure design
//processing promiseList by series in closure design
 
var PACU = require("pacu")
var pacu = new PACU(promisesList)
 
pacu.series(promisesList).then(function(result) {
    console.log("Result series: ", result)
},function(err){
    console.log("Error series: ", result)
});
 

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.6.2
    3
    • latest

Version History

Package Sidebar

Install

npm i pacu

Weekly Downloads

3

Version

1.6.2

License

ISC

Last publish

Collaborators

  • wahengchang