@joegesualdo/promise-queue

Syncronously run promises.

promise-queue

Syncronously run promises.

Install

$ npm install --save @joegesualdo/promise-queue

Usage

var PromiseQueue = require("@joegesualdo/promise-queue").default

// Create Test Promises
let promises = [];
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.name = 'joe';
    resolve(results)
  })
})
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.age = 22
    resolve(results)
  })
})

// Initailize the PromiseQueue with an array of promises
promiseQueue = new PromiseQueue(promises)

// Run all the promises syncronously.
promiseQueue.run({})
.then(function(results){
  console.log(results)
})

Test

$ npm test

API

constructor(promises)

Initializes a new PromiseQueue

Name Type Description
promises Array<Promise> Array of promises you want to run

Returns: PromiseQueue

var PromiseQueue = require("@joegesualdo/promise-queue").default

// Create Test Promises
let promises = [];
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.name = 'joe';
    resolve(results)
  })
})
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.age = 22
    resolve(results)
  })
})

promiseQueue = new PromiseQueue(promises)

run(startingObj)

Runs the promises in the order they appear in the array.

Name Type Description
startingObj Object The object that will be passed to the first promise;
var PromiseQueue = require("@joegesualdo/promise-queue").default

// Create Test Promises
let promises = [];
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.name = 'joe';
    resolve(results)
  })
})
promises.push(function(results) {
  return new Promise((resolve, reject) => {
    results.age = 22
    resolve(results)
  })
})

// Initailize the PromiseQueue with an array of promises
promiseQueue = new PromiseQueue(promises)

// Run all the promises syncronously.
promiseQueue.run({})
.then(function(results){
  console.log(results)
})

Build

$ npm run build

License

MIT © Joe Gesualdo

HomePage

https://github.com/joegesualdo/promise-queue-js#readme

Repository

git+https://github.com/joegesualdo/promise-queue-js.git