I have two third party functions which I cannot change:
One functions expects a callback that possibly could return a new data, not promise. The other function returns the new data in promise. How to connect these two functions together?
I have looked at various examples, they always suggests to use Promise.then or async await, but I don't see it applicable inside a callback.
// One 3rd party API
runExternalTransaction(callback: (currentData: any) => unknown) {
// Some 3rd party code.
}
// The other 3rd party API
getNewData(): Promise<any> {
// Some 3rd party code to get data from data storage.
}
// An attempt to put these functions together
runExternalTransaction(currentData => {
if (!currentData) { // Only return new data if current data not available.
getNewData().then(newData => ...);
// How to return new data?
return ...;
}
});