npm-promise-one
v0.0.5
Published
Resolve an array of promises one at a time
Downloads
4
Readme
Introduction
Currently there is Promise.all to resolve an array of promises concurrently. Sometime there is a need to resolve these promises one at a time.
Input an array and a callback that will use the array element to generate a promise. The second callback is to handle the data. It will then return an array of the concatenated outputs.
Example
"use strict";
const axios = require('axios');
const p = require('npm-promise-one');
const array = [1, 3, 7, 11, 51];
const url = 'https://jsonplaceholder.typicode.com/posts/';
function getPost(i) {
return axios.get(url + i);
}
function process(response) {
return response.data;
}
p.one(array, getPost, process).then(function(result) {
console.log(result);
});