Reputation: 3721
I am having trouble wrapping my head around how to make a Dojo Deferred work for the following scenario. Basically I have a function that is supposed to loop through a number of items and process each item separately in a deferred manner. It does the processing of each item in a separate method that returns a Deferred when it is done. I want to be able to execute the loop to go off and process each item and report back a success or failure when it is done. Here is what I got so far as a test sample:
http://jsfiddle.net/Ayyoudy/mgv6Y/12/
What am I doing wrong? I am expecting the output numbers to be in sequence but they are not.
I also want to be able to detect if there is an error processing one of the items and if so, not to process the rest.
Thanks
Upvotes: 2
Views: 1698
Reputation: 326
I have resolve that the output number should be in sequence. http://jsfiddle.net/granjoy/mgv6Y/17/ There're couple of issues in your code
Given that process() function will finished immediately, so the log "done processing everything!" will be first output.
Edit:
I have learn from the question. Thanks, the author gives another good solution. http://jsfiddle.net/Ayyoudy/mgv6Y/14
Upvotes: 2