Skip to content

Latest commit

 

History

History
74 lines (58 loc) · 1.02 KB

File metadata and controls

74 lines (58 loc) · 1.02 KB

promise-object

Work like Promise.all with objects any nesting level

install

node >= 8

npm i -save promise-all-object

else node versions and for webpack build

npm i -save promise-all-object@1.*

test

# test
node --expose-gc test/test.js

usage

const promiseObject = require('promise-all-object');

promiseObject({
  op1: asyncOperation(),
  op2: asyncOperation(),
  op3: 'simple field',
  op4: {
    op1: asyncOperation(),
    op2: asyncOperation(),
  },
  op5: [
    asyncOperation(),
    asyncOperation(),
  ]
}).then(res => {
  // do something...
}).catch(e => {
  console.log(e);
});

// or
async () => {
  try {
    const res = await promiseObject({
      op1: asyncOperation(),
      op2: asyncOperation(),
      op3: 'simple field',
      op4: {
        op1: asyncOperation(),
        op2: asyncOperation(),
      },
      op5: [
        asyncOperation(),
        asyncOperation(),
      ]
    });
    // do something...
  } catch (e){
    console.log(e);
  }
}