Miss any of our Open RFC calls?Watch the recordings here! »

onawait

0.0.3 • Public • Published

onawait

Async wrapper to manage try...catch blocks.

Setup

Installation

yarn add onawait
# or 
npm install onawait

Imports

import on from "onawait";
// or
import { onawait } from "onawait";

Example

import on from "onawait";
 
const hello = (name: string): Promise<string> => {
  return new Promise(resolve => {
    setTimeout(() => resolve(`Hello ${name}!`));
  });
};
 
// with try catch
(async () => {
  try {
    const greeting = await hello("Dave");
    // handle response
  } catch (error) {
    // handle error
  }
})();
 
// with "onawait"
(async () => {
  const { error, response: greeting } = await on(hello("Dave"));
 
  if (error) {
    // handle error
  }
 
  // handle response
})();

Install

npm i onawait

DownloadsWeekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

6.3 kB

Total Files

8

Last publish

Collaborators

  • avatar