await-to-js
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "await-to-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Async/await wrapper for easy error handling in js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -7,2 +7,3 @@ # await-to-js | ||
> Async await wrapper for easy error handling | ||
## Pre-requisites | ||
@@ -24,15 +25,17 @@ You need ES7 transpiler in order to use async/await functionality. | ||
async function asyncTask(cb) { | ||
const [ err, user ] = await to(UserModel.findById(1)); | ||
let err, user, savedUser, notification; | ||
[ err, user ] = await to(UserModel.findById(1)); | ||
if(!user) return cb('No user found'); | ||
const [ err, savedTask ] = await to(TaskModel({userId: user.id, name: 'Demo Task'})); | ||
[ err, savedTask ] = await to(TaskModel({userId: user.id, name: 'Demo Task'})); | ||
if(err) return cb('Error occurred while saving task'); | ||
if(user.notificationsEnabled) { | ||
const [ err ] = await to(NotificationService.sendNotification(user.id, 'Task Created')); | ||
if(err) return cb('Error while sending notification'); | ||
[ err ] = await to(NotificationService.sendNotification(user.id, 'Task Created')); | ||
if(err) return cb('Error while sending notification'); | ||
} | ||
if(savedTask.assignedUser.id !== user.id) { | ||
const [ err, notification ] = await to(NotificationService.sendNotification(savedTask.assignedUser.id, 'Task was created for you')); | ||
[ err, notification ] = await to(NotificationService.sendNotification(savedTask.assignedUser.id, 'Task was created for you')); | ||
if(err) return cb('Error while sending notification'); | ||
@@ -39,0 +42,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5755
63