Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/invertase/a2a

Async await to Array -> `const [error, value] = await A2A(fooPromise());`
https://github.com/invertase/a2a

async-await javascript promise

Last synced: 3 months ago
JSON representation

Async await to Array -> `const [error, value] = await A2A(fooPromise());`

Awesome Lists containing this project

README

        

# A2A - Async Await to Array

NPM downloads
NPM version
License

Simplify your promise workflow.

## Install

```bash
npm install --save a2a
```

## Example

```js
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
```ts
import a2a from 'a2a';

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

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

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

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