Handling custom JavaScript asynchronous events
We have a JavaScript library that lives between 2 proprietary libraries in
JavaScript (lib_Upper and lib_Lower). Our library translates returns from
lib_Lower to the values/functions lib_Upper is expecting - i.e.
lib_Upper -> lib_US -> lib_Lower
lib_Lower runs in an asynchronous way, but does not return promises or
other deferred objects. Likewise lib_Upper acts as if everything is
synchronous.
Hence, we need to convert to async to sync calls.
The process of calls is such:
lib_Upper calls lib_US.fn()
lib_US calls lib_lower.fn2()
lib_Lower sends the request over a WebSocket and returns
At this point everything bubbles back up to lib_Upper.
Some time later a response returns from the WebSocket:
lib_Lower calls lib_US.callbackFn()
lib_US library needs to return the data from lib_lower to lib_Upper
At this point we are stuck as we have already returned to lib_Upper.
Being quite new to JavaScript, it is looking quite difficult to "suspend"
the call from lib_Upper until the callback occurs.
How do we get to an asynchronous event into this chain such that lib_Upper
is only returned the data from the callback?
Thanks.
No comments:
Post a Comment