Package Exports
- await-into
- await-into/dist/index.cjs.js
- await-into/dist/index.mjs.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (await-into) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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.
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.