await-into
v1.0.5
Published
Async/await wrapper for easy error handling in js
Downloads
295
Maintainers
Readme
A utility function to handle promise resolution with automatic retries and error handling. into allows you to easily await a promise while handling potential errors in a structured format, offering retries with customizable delay.
await-into
Async await wrapper for easy error handling
Documentation • Change Log
Read this in other languages: English | 简体中文
Installing
# use pnpm
$ pnpm install await-into
# use npm
$ npm install await-into
# use yarn
$ yarn add await-into
Usage
Simple Usage
- ES6 module with no retries
import into from 'await-into'
async function example() {
const [error, result] = await into(fetchData());
if (error) {
console.error('Error:', error);
} else {
console.log('Result:', result);
}
}
2.ES6 module with retries and delay
import into from 'await-into'
async function exampleWithRetries() {
const [error, result] = await into(fetchData(), { retries: 3, retryDelay: 1000 });
if (error) {
console.error('Error after retries:', error);
} else {
console.log('Successful result:', result);
}
}
3.Node.js require
const into = require('await-into')
const [err, data] = await into(/* promise function */)
Multiple Promises
import into from 'await-into'
const bar = () => new Promise()
const foo = () => new Promise()
const [err, data] = await into(bar(), foo()) // data = [boolean, string]
// or pass in an Array
const [err, data] = await into([bar(), foo()]) // data = [boolean, string]
Using unpkg CDN
Support & Issues
Please open an issue here.