Monday, September 4th, 2006

Dojo’s Deferred API

Category: Dojo, Examples, JavaScript

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. var d = new dojo.Deferred();
  2.  
  3. // register callback
  4.  
  5. d.addCallback(function(name) {
  6.     log.debug("name: " + name)
  7. });
  8.  
  9.  
  10. // supply data
  11. d.callback("Sam Jones");

or with errors:

javascript

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

Posted by Dion Almaer at 1:57 pm
2 Comments

+++--
3.4 rating from 26 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.