Hi  there,

On 11/13/06, .M. <[EMAIL PROTECTED]> wrote:
> I've been reading the Mochikit docs for months but can't get my head
> around this construct. If there's any simpler doco on Deferred or a
> tutorial anywhere, please let me know.

Check this out:
http://twistedmatrix.com/projects/core/documentation/howto/async.html#auto5

In your case:

var d = null;  // a global var for the deferred

function check() {
   global d;
   d.loadJSON("/foo/bar");
   d.addCallback(resultsItem);
}

function resultsItem(theData) {
  // the parameter "theData" contains the result of the JSON call

  checks = something;
  return checks;
}

function business() {
  check();

  // don't go forward until results of check are handled
  // You can't "suspend" execution here because you'll be suspending
  // the main event loop. Without the event loop running, you'll never get
  // the result. You can however add another call back to the d.
  d.addCallback(function (checks) {
    // this callback will be called with the result of the callback
    // just before it in the deferred's chain of callbacks - in this case
    // it's the "checks" stuff you return from resultsItem
  });

  do something reliant on check() being accurate;
}

Arnar

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to