Hi,
I am working with an API that is callback based (think alternating sets of request and requestCompleted messages) and in an attempt to avoid writing an ugly and difficult-to-maintain chain of nested callbacks, I am looking for a way to convert those calls into a function that only returns when the reply is received. I thought of two ways of doing this, but both seem like a bit of a hack to me and I was wondering if there was a more cleaner/native way.
The first was to use q’s C interface to add a layer between my app and the API endpoint (both q processes), taking a synchronous request, sending it on as an asynchronous call, and replying to the client only when it received the asynchronous reply. (You would open two sockets, listening to one and then sending on the other, alternately.) The second was to use Andrey Kozyrev’s debugger to run my app, adding in breakpoints where I needed to wait for asynchronous replies, and continuing execution when I received a callback. (The new debugger doesn’t seem to be able to pause and resume execution.)
Neither of those seem efficient, so I was wondering if there was a more native way to either 1) respond to a synchronous call asynchronously, or 2) pause execution of the script while responding to network events, and resuming when a callback was received.
Thanks for your help,
Victor