All Projects → KyleRoss → Await Handler

KyleRoss / Await Handler

Licence: mit
Basic wrapper for await that allows handling of errors without try/catch blocks

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Await Handler

of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (+0%)
Mutual labels:  promise, error-handling, await, async-await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (+1746.15%)
Mutual labels:  promise, error-handling, async-await, await
P Map
Map over promises concurrently
Stars: ✭ 639 (+4815.38%)
Mutual labels:  promise, async-await, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+2492.31%)
Mutual labels:  promise, async-await, await
Log Process Errors
Show some ❤️ to Node.js process errors
Stars: ✭ 424 (+3161.54%)
Mutual labels:  promise, error-handling, handler
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (+61.54%)
Mutual labels:  promise, error-handling, async-await
run exclusive
⚡🔒 Wait queue for function execution 🔒 ⚡
Stars: ✭ 22 (+69.23%)
Mutual labels:  promise, async-await
Evt
💧EventEmitter's typesafe replacement
Stars: ✭ 305 (+2246.15%)
Mutual labels:  promise, async-await
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+28969.23%)
Mutual labels:  promise, async-await
await-generator
A library to use async/await in PHP using generators.
Stars: ✭ 80 (+515.38%)
Mutual labels:  await, async-await
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (+2515.38%)
Mutual labels:  async-await, await
Basic Ftp
FTP client for Node.js, supports FTPS over TLS, passive mode over IPv6, async/await, and Typescript.
Stars: ✭ 441 (+3292.31%)
Mutual labels:  promise, async-await
Ws Promise Client
PROJECT MOVED: https://github.com/kdex/ws-promise
Stars: ✭ 6 (-53.85%)
Mutual labels:  promise, await
kbio
Another Async IO Framework based on io_uring
Stars: ✭ 54 (+315.38%)
Mutual labels:  await, async-await
Express Promise Router
A lightweight wrapper for Express 4's Router that allows middleware to return promises
Stars: ✭ 309 (+2276.92%)
Mutual labels:  promise, async-await
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+546.15%)
Mutual labels:  await, async-await
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+4023.08%)
Mutual labels:  promise, async-await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+5207.69%)
Mutual labels:  async-await, await
Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+5761.54%)
Mutual labels:  promise, await
debounce-async
A debounce function that delays invoking asynchronous functions.
Stars: ✭ 21 (+61.54%)
Mutual labels:  promise, async-await

await-handler

npm npm David Travis license Beerpay

Simple signature to ease the paid of catching errors using async/await. This module will allow a simple method of catching errors from an await handler without the need to wrap everything in try/catch blocks. This module is a Node.js only version based on await-to-js minus the typescript aspect. Credit for this module goes to Dima Grossman, as it was based off the code provided.

You continue to use async/await normally, except to wrap the function you are "awaiting", in this module to allow destructuring the returned array into variables. This is similar to the golang error handling syntax.

NOTE: This module works in Node 6+, but in order to use async/await, you need to use Node 8+ or compile with Babel.

Install

Install via NPM:

npm i await-handler --save

Usage

const on = require('await-handler');

async function asyncFunctionExample() {
    let [err, result] = await on(myAsyncTask());
    if(err) {
        throw err;
    }
    
    // ... handle the result
    console.log(result);
}

API

on(promise[, errorProps])

Type: Function

Adds handler to promise in order to return an array which can be destructured. Optionally add additional properties to the returned error by providing an Object to errorProps.

Argument Required? Type Description
promise Yes Promise Promise to wrap and return results for.
errorProps No Object Optional object to append to the Error if one is thrown.

Examples:

async function basicExample() {
    let [err, result] = await on(myAsyncTask());
    if(err) throw err;
    
    // ... handle the result
    console.log(result);
}

async function errorPropsExample() {
    let [err, result] = await on(myAsyncTask(), { customMessage: 'Something failed!' });
    if(err) {
        console.error(err.customMessage);
        return process.exit(1);
    }
    
    // ... handle the result
    console.log(result);
}
Returns {Promise<Array>}

Returns Promise that resolves with array signature [error, results]. If an error is thrown, error will be the the rejection from the promise and results will be undefined. If an error is not thrown, error will be null and results will be the resolved value from the promise.


Tests

To run the tests:

npm install
npm run test

License

MIT License. See License in the repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].