advance-await

1.0.9 • Public • Published

Advance Await: Simplified Async Error Handling 🚀

Tired of writing repetitive try-catch blocks? Advance Await introduces an elegant way to handle errors in async functions and Promises using [error, result] tuples—no more cluttered error handling!

✨ Why Use Advance Await?

No More try-catch Hell – Get rid of unnecessary boilerplate.
Effortless Async Handling – Errors are caught automatically.
Works with Functions & Promises – Compatible with fetch(), JSON parsing, and more!
Flexible Usage – Use it globally or import per file.


🚀 Installation

Install the package using npm, yarn, or pnpm:

npm install advance-await
# OR
yarn add advance-await
# OR
pnpm install advance-await

🔧 Usage Methods

You can use Advance Await in two ways:

1️⃣ Global Import (Use Everywhere Automatically) 🌍

To enable Advance Await globally in your project without manual imports, run your script with:

tsx --require=advance-await src/your-script.ts
node --require advance-await src/your-script.js

Now, every async function and promise in your project can use [error, result] without needing an import!

(async () => {
    const [error, response] = await fetch("https://jsonplaceholder.typicode.com/posts/1")[Symbol.result]();
    if (error) return console.error("Fetch error:", error.message);

    const [jsonError, data] = await response.json()[Symbol.result]();
    if (jsonError) return console.error("JSON parsing error:", jsonError.message);

    console.log(data);
})();

2️⃣ Single File Import (For Selective Usage) 📄

If you prefer using it in a specific file only, simply import advance-await at the top:

import "advance-await";  // Just import once per file!

(async () => {
    const [error, response] = await fetch("https://jsonplaceholder.typicode.com/posts/1")[Symbol.result]();
    if (error) return console.error("Fetch error:", error.message);

    const [jsonError, data] = await response.json()[Symbol.result]();
    if (jsonError) return console.error("JSON parsing error:", jsonError.message);

    console.log(data);
})();

🔹 No need for try-catch—errors are automatically caught in [error, result].
🔹 Works seamlessly with any async function or Promise.


📜 License

MIT

Say goodbye to try-catch clutter and write cleaner, more readable async code today! 🚀

Readme

Keywords

none

Package Sidebar

Install

npm i advance-await

Weekly Downloads

9

Version

1.0.9

License

MIT

Unpacked Size

3.71 kB

Total Files

3

Last publish

Collaborators

  • prashant.vr