All Projects → scopsy → Await To Js

scopsy / Await To Js

Licence: mit
Async await wrapper for easy error handling without try-catch

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Await To Js

Ea Async
EA Async implements async-await methods in the JVM.
Stars: ✭ 1,085 (-51.19%)
Mutual labels:  async, async-await
Async Backplane
Simple, Erlang-inspired fault-tolerance framework for Rust Futures.
Stars: ✭ 113 (-94.92%)
Mutual labels:  async, async-await
Tascalate Async Await
Async / Await asynchronous programming model for Java similar to the functionality available in C# 5. The implementation is based on continuations for Java (see my other projects).
Stars: ✭ 60 (-97.3%)
Mutual labels:  async, async-await
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+270.94%)
Mutual labels:  async, async-await
Futures Intrusive
Synchronization primitives for Futures and async/await based on intrusive collections
Stars: ✭ 137 (-93.84%)
Mutual labels:  async, async-await
Preact Cli Plugin Async
Preact CLI plugin that adds converts async/await to Promises.
Stars: ✭ 44 (-98.02%)
Mutual labels:  async, async-await
Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-94.96%)
Mutual labels:  async, async-await
Chillout
Reduce CPU usage by non-blocking async loop and psychologically speed up in JavaScript
Stars: ✭ 565 (-74.58%)
Mutual labels:  async, async-await
Cppcoro
A library of C++ coroutine abstractions for the coroutines TS
Stars: ✭ 2,118 (-4.72%)
Mutual labels:  async, async-await
Nim Chronos
Chronos - An efficient library for asynchronous programming
Stars: ✭ 136 (-93.88%)
Mutual labels:  async, async-await
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (-59.15%)
Mutual labels:  async, async-await
Unityfx.async
Asynchronous operations (promises) for Unity3d.
Stars: ✭ 143 (-93.57%)
Mutual labels:  async, async-await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (-68.96%)
Mutual labels:  async, async-await
Create React Redux App
This project was bootstrapped with Create React App and Redux, Sass Structure.
Stars: ✭ 46 (-97.93%)
Mutual labels:  async, async-await
P Map
Map over promises concurrently
Stars: ✭ 639 (-71.26%)
Mutual labels:  async, async-await
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-96.4%)
Mutual labels:  async, async-await
Trio
Trio – a friendly Python library for async concurrency and I/O
Stars: ✭ 4,404 (+98.11%)
Mutual labels:  async, async-await
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (-75.89%)
Mutual labels:  async, async-await
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-94.02%)
Mutual labels:  async, async-await
Asynquence
Asynchronous flow control (promises, generators, observables, CSP, etc)
Stars: ✭ 1,737 (-21.86%)
Mutual labels:  async, async-await

await-to-js

NPM version Downloads

Async await wrapper for easy error handling

Supported by:
The open-source notification infrastructure

Pre-requisites

You need to use Node 7.6 (or later) or an ES7 transpiler in order to use async/await functionality. You can use babel or typescript for that.

Install

npm i await-to-js --save

Usage

import to from 'await-to-js';
// If you use CommonJS (i.e NodeJS environment), it should be:
// const to = require('await-to-js').default;

async function asyncTaskWithCb(cb) {
     let err, user, savedTask, notification;

     [ err, user ] = await to(UserModel.findById(1));
     if(!user) return cb('No user found');

     [ err, savedTask ] = await to(TaskModel({userId: user.id, name: 'Demo Task'}));
     if(err) return cb('Error occurred while saving task');

    if(user.notificationsEnabled) {
       [ err ] = await to(NotificationService.sendNotification(user.id, 'Task Created'));
       if(err) return cb('Error while sending notification');
    }

    if(savedTask.assignedUser.id !== user.id) {
       [ err, notification ] = await to(NotificationService.sendNotification(savedTask.assignedUser.id, 'Task was created for you'));
       if(err) return cb('Error while sending notification');
    }

    cb(null, savedTask);
}

async function asyncFunctionWithThrow() {
  const [err, user] = await to(UserModel.findById(1));
  if (!user) throw new Error('User not found');
  
}

TypeScript usage

interface ServerResponse {
  test: number;
}

const p = Promise.resolve({test: 123});

const [err, data] = await to<ServerResponse>(p);
console.log(data.test);

License

MIT © Dima Grossman && Tomer Barnea

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