I’ve been doing a lot of heavy lifting in back-end workflows. I’ve found I am repeatedly using the following pattern that mimicks the await
operator:
// Make a promise
var holder = maker(... )
// Try to fulfil the promise
var fulfilment = context.async(
callback => holder
.then(fulfilled => callback(null, fulfilled))
.catch(reason => callback(reason))
);
I was wondering if this could be fomalized into the context
object:
context[await] = holder => !(holder instanceof Promise) ? holder : context.async(
callback => holder
.then(fulfilled => callback(null, fulfilled))
.catch(reason => callback(reason))
);