function to(promise) {
return promise
.then(data => {
return [null, data];
})
.catch(err => [err]);
}
async function asyncTask(cb) {
let err, user, savedTask;
console.log(111, savedTask)
[err, user] = await to(Promise.resolve('error1'));
if (!user) return cb("No user found");
[err, savedTask] = await to(Promise.resolve('error2'));
if (err) return cb("Error occurred while saving task");
cb(null, savedTask);
}
asyncTask((v, k) => {
console.log(222, v, k)
})