... The function returned by $Y (the wrapping function) meets the following requirements: * It always returns an instance of {{jsx3.$AsyncRV}}. * It can take any of a number of parameters. Consult the API documentation of the function for the expected parameters. h3. A Simple Example Any function passed to the {{when()}} method of {{jsx3.$AsyncRV}} is called when the asynchronous method is done. The function is passed a single parameter, which is the asynchronous return value of the asynchronous function, as in the following example: {code:lang=javascript}var rv = loadXmlAsync("data.xml"); rv.when(function(doc) { jsx3.log("The asynchronous return value is: " + doc); });{code} h3. Multiple Callbacks A program can call {{when()}} any number of times before or after the asynchronous method finishes. Regardless of when it is called, all callbacks are invoked. For example: {code:lang=javascript}var rv = loadXmlAsync("data.xml"); rv.when(function(doc) { jsx3.log("Got document: " + doc); }); rv.when(function(doc) { doSomethingElse(doc); });{code} h3. Condition Chaining Use the {{and()}} and {{or()}} methods of {{jsx3.$AsyncRV}} to chain asynchronous return conditions. Both methods also return instances of {{jsx3.$AsyncRV}}. For example: {code:lang=javascript}var rv1 = loadXmlAsync("data1.xml"); var rv2 = loadXmlAsync("data2.xml"); rv1.and(rv2).when(function() { jsx3.log("Got docs: " + rv1.rv() + " and " + rv2.rv()); });{code} h3. Automatic Parameter Resolution If an instance of {{jsx3.$AsyncRV}} is passed as a parameter to an asynchronous function, the function automatically waits for the parameter to be available before calling the wrapped function.
|