• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

While not javascript code, callback inside a callback inside a callback

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks

Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would this not fit better in the Groovy forum?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it doesn't get responses here either. ;)

callbacks inside of callbacks, makes me start to think recursive callbacks.

Anyway thanks for trying.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic