I'm writing code in Typescript and I'm having trouble with libraries which lack synchronic functions/methods. I just need to wait for a promise to be resolved and I can't find a reasonable way of doing so. What I intend to do is just:
public someObjectMethod(): any {
externalLibrary.doSomeghing()
// wait for that something to happen
// continue doing stuff
I know I can make the method async
so it returns a Promise
and then declare the calling method async
too so that it also returns a Promise
and so on until I eventually get to a point where I can await
, but if I do that I'll end up with an object model where every method is async
and every object is a Promise
. The thing is that I took Typescript for this expecting to be able to write OO code and not a Javascript script. I don't think using Promises
, async
and await
will scale in a big OO model and I really don't need the extra performance I can get from asynchronous calls but rather the flow control I can get from synchronous calls.
So the question is... Is there a - reasonable - way to wait for Promises
to resolve?
THIS IS NOT A DUPLICATE QUESTION!
I'm asking if there's a reasonable way of waiting for a Promise
to resolve in the context of writing an object-oriented model. Changing all functions in the call trace to async
and then handling Promises
everywhere is not a reasonable way of solving this problem. I need to know if there's a way of just waiting for a Promise
to resolve instead of changing the signature of half my code every time I come across a library which doesn't have synchronous implementations.