Activate your free membership today | Log-in

Monday, September 4th, 2006

Dojo’s Deferred API

Category: Dojo, Examples, JavaScript

<>p>Brian McCallister has written more about Dojo Deferred and DFS in which he talks about the new Dojo Deferred class based on MochiKits and Twisteds.

JAVASCRIPT:
  1.  
  2. var d = new dojo.Deferred();
  3.  
  4. // register callback
  5.  
  6. d.addCallback(function(name) {
  7.     log.debug("name: " + name)
  8. });
  9.  
  10.  
  11. // supply data
  12. d.callback("Sam Jones");
  13.  

or with errors:

JAVASCRIPT:
  1.  
  2. var d = new dojo.Deferred();
  3. d.addCallback(function(v) { log.debug("success! : "  + v) })
  4. d.addErrback(function(e) { log.debug("error! : " + v) })
  5.  
  6.  
  7. if (Math.random()> 0.5) {
  8.     d.callback("yea!")
  9. }
  10. else {
  11.     d.errback("boo!")
  12. }
  13.  

Related Content:

Posted by Dion Almaer at 1:57 pm
2 Comments

+++--
3.5 rating from 21 votes

2 Comments »

Comments feed TrackBack URI

To give credit where it’s due, Dojo’s Deferred API is a direct port from MochiKit’s excellent implementation. All credit for this goes to Bob, and errors in the implementation are quite certainly ours.

Regards

Comment by Alex Russell — September 4, 2006

I’m not the smartest JS-kid in town, but shouldn’t that read:
d.addErrback(function(e) { log.debug(“error! : ” + e) })?

Comment by Matthias — September 5, 2006

Leave a comment

You must be logged in to post a comment.