Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

await-it

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

await-it

A wrapper for async/await calls without the need of try/catch block.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Await it

A wrapper for async/await calls without the need of try/catch block.

If someone told you that you should try / catch once at the root of your application and then do your async calls anywhere in the codebase, they are wrong. You should try / catch every async / await call or use .then() / .catch() chainables. Better than callback hell? I think it leads to similar problem...

This module attempts to solve that nesting hell and instead provide clean and fluent api with tuple destructuring.


Installation (pick one)

  • npm i await-it
  • yarn add await-it

Usage

We'll pretend that we have some kind of Promise already declared globally, to avoid bulky README file.

// Fake Global Promises
const fakeResolve = Promise.resolve({ name: 'Nenad Novakovic', age: 28 })
const fakeReject = Promise.reject(new Error('Rejection reason...'))

Without TypeScript

import { it } from 'await-it'

(async () => {
  const [res, err] = await it(fakeResolve);

  console.log(res) // { name: 'Nenad Novakovic', age: 28 }
  console.log(err) // null
})()

(async () => {
  const [res, err] = await it(fakeReject);

  console.log(res) // undefined
  console.log(err.message) // Rejection reason...
})

With TypeScript

import { it } from 'await-it'

(async () => {
  interface User {
    name: string;
    age: number;
  }

  const [res] = await it<User>(fakeResolve);

  console.log(res) // { name: 'Nenad Novakovic', age: 28 }
})()

Node Environment

// Import as CommonJS
const { it } = require('await-it')

// Import as ESM 
import { it } from 'await-it'

Keywords

FAQs

Package last updated on 03 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc