A2A - Async Await to Array
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) {
}
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) {
}
console.log('Users', users);
console.log('Profile', profile);
}
example1();
example2();
TypeScript
import a2a from 'a2a';
a2a(Promise.resolve(123))
.then(([error, result]) => {
console.log(result as number);
});
a2a<number|string>(Promise.resolve('123'));
a2a<number|string>([Promise.resolve('123')]);
a2a<number|string, Error>(Promise.resolve('123'));