@
TomatoYuyuko 我是参考了这个
https://blog.grossman.io/how-to-write-async-await-without-try-catch-blocks-in-javascript/import to from './to.js';
async function asyncTask() {
let err, user, savedTask;
[err, user] = await to(UserModel.findById(1));
if(!user) throw new CustomerError('No user found');
[err, savedTask] = await to(TaskModel({userId:
user.id, name: 'Demo Task'}));
if(err) throw new CustomError('Error occurred while saving task');
if(user.notificationsEnabled) {
const [err] = await to(NotificationService.sendNotification(
user.id, 'Task Created'));
if (err) console.error('Just log the error and continue flow');
}
}