rsp / deno-caught

Deno port of https://github.com/rsp/node-caught

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deno caught

This module lets you attach empty rejcetion handlers to promises to avoid errors when we want to handle rejections asynchronously.

It is a port of caught for Node, see: https://github.com/rsp/node-caught

More info

Doing something like this:

const p = Promise.reject(0);

setTimeout(() => p.catch(e => console.error('caught')), 0);

will result in the program terminating with an error:

error: Uncaught 0

This module lets you write:

const p = caught(Promise.reject(0));

setTimeout(() => p.catch(e => console.error('caught')), 0);

to avoid those errors on a per-promise basis.

Use at your own risk.

Background

For more info see this answer on Stack Overflow:

Usage

import { caught } from 'https://deno.land/x/caught/mod.ts';

const p = caught(Promise.reject(0));

Note that it is not the same as writing:

const p = Promise.reject(0).catch(() => {});

which would not return the original promise and wouldn't let you add catch handlers later.

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Rafał Pocztarski
Follow on GitHub Follow on Twitter
Follow on Stack Exchange

Contributors

License

MIT License (Expat). See LICENSE.md for details.

About

Deno port of https://github.com/rsp/node-caught

License:MIT License


Languages

Language:TypeScript 57.0%Language:Shell 43.0%