Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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());`
- Host: GitHub
- URL: https://github.com/invertase/a2a
- Owner: invertase
- License: other
- Created: 2018-09-09T19:41:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-10T10:11:28.000Z (about 2 years ago)
- Last Synced: 2024-04-25T17:05:45.859Z (9 months ago)
- Topics: async-await, javascript, promise
- Language: JavaScript
- Size: 26.4 KB
- Stars: 7
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A2A - Async Await to Array
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'));
```