I'm working in a medium sized node.js application with a series of synchronous functions that call other synchronous functions, etc. For the sake of simplicity let's just say that none of these functions returned Promises before this.
function a(){
...
return c();
}
function b(){
...
return c();
}
function c(){
...
return e();
}
function d(){
...
return e();
}
function e(){
// Do stuff
}
It's actually much more complex than this and has a full suite of unit/integration tests that call these functions as well.
We now need to function e() to wait for the result of an async function:
function e(){
const someData = await someAsyncFunction();
const dataINeedNow = someData.dataINeedNow;
// Do something with dataINeedNow
}
async function someAsyncFunction(){
...
return await someExternalService();
}
It seems like the general wisdom is that once you start returning Promises you should keep returning Promises. In the example above this would involve making a, b, c, d and e all async
, but in reality it would involve ~100 changes in our application.
Is there a way to make a single call to await someExternalService();
in the bowels of a node.js application without a major refactor?