This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Figured you guys would be the best at thinking this through more than other forums that might be a little bit more appropriate.
So I actually have a situation where I have 5 levels of callbacks to get a use case finished. I am using Groovy, but with closures it is very much like how we would code these callbacks with Javascript.
So the scenario is 100% async everywhere.
so the steps are
1) call a db async to lookup some data.
2) When the async reply callback is called with the found data
3) take that data and create an update statement to send to db
4) async call to the db to run the update
5) after the async update returns send an AMQP messaging async message to a Queue
6) when the async response comes back create an update statement to the db
7) send the db call async.
8) what it returns send a reply back to the user.
In my code I have things like
So in that scenario anotherMethod should run and its callback get called then go on to the following code
def innerCallBack = {reply ->
}
callSomeOtherAsyncMethod innerCallBack
But it doesn't wait, it just goes directory to callSomeOtherAsyncMethod before the callback in anotherMethod even runs.
So what do I need to put in there to make it actually "waterfall" and runn all the callbacks serially. What don't I see that I am doing wrong.
Bear Bibeault wrote:Would this not fit better in the Groovy forum?
No because it isn't really a Groovy specific question, it is a Callback, callback, callback question that happens way more in JavaScript than in Groovy. Matter of fact Groovy doesn't have anything built in, nor does it happen this way 99.9% of the time in Groovy. So the experts in JavaScript would understand it better and be able to answer in the design way, since most of the time in JavaScript we have callbacks within callbacks. So I want a design idea from Javascript people, not Groovy. I expect in Groovy, I won't ever get a reply on this subject.
Does that make sense. The language actually has no relation to the question I am asking. But the experience of Javascript developers will definitely understand the issues with async callbacks within async callbacks within async callbacks.