All Projects → coderaiser → try-to-catch

coderaiser / try-to-catch

Licence: MIT license
functional try-catch wrapper for promises

Programming Languages

javascript
184084 projects - #8 most used programming language
HCL
1544 projects

Projects that are alternatives of or similar to try-to-catch

of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-56.67%)
Mutual labels:  promise, await, try-catch
Promise
Asynchronous Programming with Promises
Stars: ✭ 15 (-50%)
Mutual labels:  promise, catch, await
try-inline
An easy inline error handling wrapper for async promises and syncronous functions
Stars: ✭ 24 (-20%)
Mutual labels:  try, await, try-catch
go-try
A package that allows you to use try/catch block in Go.
Stars: ✭ 37 (+23.33%)
Mutual labels:  catch, try, try-catch
ws-promise
A tiny, Promise-based WebSocket protocol allowing request-response usage in ECMAScript
Stars: ✭ 20 (-33.33%)
Mutual labels:  promise, await
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-33.33%)
Mutual labels:  promise, await
combine-promises
Like Promise.all(array) but with an object instead of an array.
Stars: ✭ 181 (+503.33%)
Mutual labels:  promise, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+1023.33%)
Mutual labels:  promise, await
Log Process Errors
Show some ❤️ to Node.js process errors
Stars: ✭ 424 (+1313.33%)
Mutual labels:  promise, error
P Map
Map over promises concurrently
Stars: ✭ 639 (+2030%)
Mutual labels:  promise, await
Ws Promise Client
PROJECT MOVED: https://github.com/kdex/ws-promise
Stars: ✭ 6 (-80%)
Mutual labels:  promise, await
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+210%)
Mutual labels:  promise, await
Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+2440%)
Mutual labels:  promise, await
Await Handler
Basic wrapper for await that allows handling of errors without try/catch blocks
Stars: ✭ 13 (-56.67%)
Mutual labels:  promise, await
organiser
An organic web framework for organized web servers.
Stars: ✭ 58 (+93.33%)
Mutual labels:  promise, await
best-queue
Queue in runtime based promise
Stars: ✭ 26 (-13.33%)
Mutual labels:  promise, await
relaks
Asynchrounous React component
Stars: ✭ 49 (+63.33%)
Mutual labels:  promise, await
Emacs Async Await
Async/Await for Emacs
Stars: ✭ 47 (+56.67%)
Mutual labels:  promise, await
WebsocketPromisify
Makes websocket's API just like REST with Promise-like API, with native Promises.
Stars: ✭ 18 (-40%)
Mutual labels:  promise, await
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (+10%)
Mutual labels:  promise, await

Try to Catch NPM version Build Status Coverage Status

Functional try-catch wrapper for promises.

Install

npm i try-to-catch

API

tryToCatch(fn, [...args])

Wrap function to avoid try-catch block, resolves [error, result];

Example

Simplest example with async-await:

const tryToCatch = require('try-to-catch');
const reject = Promise.reject.bind(Promise);
await tryToCatch(reject, 'hi');
// returns
// [ Error: hi]

Can be used with functions:

const tryToCatch = require('try-to-catch');
await tryToCatch(() => 5);
// returns
[null, 5];

Advanced example:

const {readFile, readdir} = require('fs/promises');
const tryToCatch = require('try-to-catch');

read(process.argv[2])
    .then(console.log)
    .catch(console.error);

async function read(path) {
    const [error, data] = await tryToCatch(readFile, path, 'utf8');
    
    if (!error)
        return data;
    
    if (error.code !== 'EISDIR')
        return error;
    
    return await readdir(path);
}

Related

License

MIT

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].