I am not a JS/TS dev, however I have to add one thing is some frontend project written in TS.
Let me describe it shortly. I have a list of functions which are executed sequentially. The first defined result found is then returned and the rest of functions are not executed then. So let's say, I have functions: [fun1, fun2, fun3, fun4, fun5]
and fun1, fun2
return undefined
for given args and fun3
returns some value - fun4, fun5
are not executed then and the result from fun3
is returned from a caller function. All functions are synchronous.
Now, I have to add a new function with GET request. I will add it to the mentioned array, but HTTP call makes it a bit problematic. I would have to work with async/await model or promises and then
callback, but as I understand, it does not give me any chance to wait for a result in a synchronous method.
Unfortunately, it is not possible to refactor the existing code to make it async.
Is there any way to integrate blocking IO call into the existing synchronous code?
export function myProblematicFunction(...some args...): SomeReturnVal {
// I want to make a GET call here, post-process it and return it as SomeReturnVal
}