Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Await To Js | 2,476 | 644 | 275 | a year ago | 7 | March 09, 2021 | 7 | mit | TypeScript | |
Async await wrapper for easy error handling without try-catch | ||||||||||
Await Result | 11 | 1 | 2 | 3 years ago | 17 | February 24, 2020 | 1 | mit | TypeScript | |
Error handling for async functions without try/catch blocks | ||||||||||
Asyncawait Typescript Example | 2 | 8 years ago | HTML | |||||||
AsyncAwait-TypeScript-Example | ||||||||||
Netlify Cog | 2 | 7 years ago | apache-2.0 | JavaScript | ||||||
A cog to use with Operable to manage Netlify sites. | ||||||||||
Errisy Tsc | 1 | 6 years ago | JavaScript | |||||||
a customized typescript compiler transpiler | ||||||||||
Express Mongoose Api Es6 Example | 1 | 5 years ago | mit | JavaScript | ||||||
This is a simple starter project example using express, mongoose with es6 code without any transpiler. | ||||||||||
Atom Js Transpiler | 1 | 9 years ago | Python | |||||||
Async await wrapper for easy error handling
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.
npm i await-to-js --save
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');
}
interface ServerResponse {
test: number;
}
const p = Promise.resolve({test: 123});
const [err, data] = await to<ServerResponse>(p);
console.log(data.test);
MIT © Dima Grossman && Tomer Barnea