Rewriting Callbacks with Promises
We are recently in the mist of the rewrite of the codebase. Since the promises inside of promises and callbacks inside of callbacks are apparently undebugable, we are rewriting away all the callbacks.
But we are also using some of the other libraries in the codebase, and not all of them support the promises structure yes. Which is a bit of annoyance, since we are now getting no feedback, when something fails inside of the callback.
So what it is possible to do, is to wrap the function into a new Promise structure, and then await that.
So for example, if I have a function with the callback in this form:
function name() { return function(arguments, (data) => {resolve(data)}) }
then I can rewrite the function into this:
function name() { new Promise((resolve, reject) => { function(arguments, (data) => {resolve(data)}) }); }
This allows us to use the function as if they returned the promises, along with all the more readable syntax like await and so on. Which is nice, because I like the more readable code, callbacks are not really readable.