Oh Baby Oh How my Business did Grow - dojo.DeferredList


Oh baby oh!

Wow, so I was about to develop a REST service that gives me json for a drop down list.  But I have 4 lists coming from 4 database tables.  I was debating with myself... should I make 1 service or 4?  I need other data too.  Maybe I should lump it all together in one big web service?  Then I was thinking of reuse... that service is not very reusable.  If I made a service for each list, I could use them in other situations.  OK cool.  Then I start thinking of the code.  In one app I made in the past, I chained the REST calls and even made an object that would handle the chaining and callbacks for me.  Looking back, that was a big mistake.  Why?

dojo.DeferredList, that's why.


I did a quick google search for dojo chain xhrget requests.  DeferredList is the 3rd hit.  So it turns out that instead of calling 4 REST services in series, you can call them in parallel!  Dude if I'm late to the party, sorry, but this just blew my mind.  In other words, if the services take 400 ms, 300 ms, 500 ms and 200 ms to execute when called by themselves, instead of chaining them together and waiting 1.4 seconds, you get the results in 500ms.  Beautiful!

Comments

Popular Posts