Async await to Array -> `const [error, value] = await A2A(fooPromise());`
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.editorconfig
.gitignore
.npmignore
LICENSE Open source commit Sep 10, 2018
README.md Update README.md for typescript Nov 9, 2018
index.d.ts add typescript definitions Nov 9, 2018
index.js cleanup & remove redundant functionality Sep 10, 2018
package-lock.json 0.2.0 Nov 14, 2018
package.json 0.2.0 Nov 14, 2018
tsconfig.json add types test Nov 9, 2018

README.md

A2A - Async Await to Array

NPM downloads NPM version License

Simplify your promise workflow.

Install

npm install --save a2a

Example

const A2A = require('a2a');
const axios = require('axios');

async function example1() {
  const [ error, users ] = await A2A(axios.get('https://api.com/users'));
  if (error) {
    // ... do something
  }

  console.log('Users', users);
}

async function example2() {
  const [ error, [ users, profile ] ] = await A2A([
    axios.get('https://api.com/users'),
    axios.get('https://api.com/profile'),
  ]);
  
  if (error) {
    // ... do something
  }
  
  console.log('Users', users);
  console.log('Profile', profile);
}

example1();
example2();

TypeScript

import a2a from 'a2a';

a2a(Promise.resolve(123)) // => Promise<[any, number]>
  .then(([error, result]) => {
    console.log(result as number);
  });

// => Promise<[any, number|string]>
a2a<number|string>(Promise.resolve('123'));

// => Promise<[any, Array<number|string>]>
a2a<number|string>([Promise.resolve('123')]);

// => Promise<[Error, number|string>>
a2a<number|string, Error>(Promise.resolve('123'));