New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Cannot you just define a simple function wrapAwait like this:
function wrapAwait(func){
return function(...args) {
return new Promise((resolve, reject)=>{
func(...args, (...callbackArgs)=>{
resolve(callbackArgs);
});
});
};
}
and use it like
const getFromDbA = wrapAwait(getFromDb);
let [error, data] = await getFromDbA(1);
?
Of course you still have to worry about the original function raising an exception.