I need to implement the following usage for functionA
functionA(url).then((result) => process(result))
The problem is that, to get result
, functionA calls an asynchronous functionB inside, and the only way to get result
out of functionB is via a callback.
I know the following solution it is definitely wrong, as it returns undefined, but I thought maybe it is a good start
async function functionA(url) {
return new Promise((resolve, reject) => {
let outerResult
const callback = (result) => {
outerResult = result
}
functionB(url, callback)
resolve(outerResult)
})
}
PS: the reason functionB can only return values via a callback is that it adds its request for results to a collection of requests, and based on priority the requests are then fired. I cannot think of anyway other than callback to return the result
from functionB.