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.

Usage no npm install needed!

<script type="module">
  import pacu from 'https://cdn.skypack.dev/pacu';
</script>

README

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