aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes While not javascript code, callback inside a callback inside a callback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "While not javascript code, callback inside a callback inside a callback" Watch "While not javascript code, callback inside a callback inside a callback" New topic
Author

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

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Would this not fit better in the Groovy forum?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: While not javascript code, callback inside a callback inside a callback