Skip to main content link. Accesskey S
  • Translate Page ▼
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Mashup Center wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 2.0
  • 3.0
  • 3.0.0.1
  • action widgets
  • actions
  • admin
  • administering
  • administration
  • administrator
  • adminstering
  • Ajax
  • AJAX proxy
  • annotate function
  • annotator
  • API
  • api reference
  • benchmark testing
  • catalog
  • configuing
  • configuration
  • configure
  • configuring
  • creating
  • creating mashups
  • data
  • data mashup builder
  • data mashups
  • database
  • DB2
  • demo
  • deploy
  • deployment
  • designing applications
  • developer
  • developing
  • developing mashups
  • developing widgets
  • documentation
  • ECM Widgets
  • editing
  • Enterprise Content Management Widgets
  • errors
  • events
  • examples
  • explanations
  • feed
  • feed mashups
  • feeds
  • format
  • functions
  • getting started
  • greenhouse
  • guide
  • IMS database feeds
  • IMS feeds
  • IMS transaction feeds
  • installation
  • installing
  • mashup
  • MashupHub
  • mashuphub examples
  • mashuphub users guide
  • mashups
  • messages
  • migrating
  • objects
  • operators
  • Oracle
  • pages
  • payload types
  • pdf
  • performance
  • performance tuning
  • planning
  • product
  • programming
  • proxy
  • rest services
  • security
  • service
  • spaces
  • themes
  • troubleshooting
  • tutorial
  • tutorials
  • upgrading
  • user
  • users
  • v1.0
  • v1.1
  • v2.0
  • v2.0.0.2
  • v4.5.2.1
  • video
  • WAR
  • widget
  • widgets
  • widgets
  • wire
  • YouTube
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > Developing > Working with asynchronous operations: Examples of using the Mashup Center 2.0 JavaScript Enabler API
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Working with asynchronous operations: Examples of using the Mashup Center 2.0 JavaScript Enabler API  

expanded Abstract
collapsed Abstract
No abstract provided.
ShowTable of Contents
HideTable of Contents
  • 1 Working with deferred objects
This article provides examples of how to use the Mashup Center JavaScript API with deferred objects.

Certain operations of the JavaScript Enabler API involve handling HTTP requests. Deferred objects allow to synchronously and asynchronously handle such operations. For such handling, deferred objects allow to define callbacks, which are invoked at specific points in time of such operations. For example, a foreachCallback allows to invoke a callback for each iteration of an iterator, or a finishedCallback allows to invoke a callback after the whole operation finished.

Working with deferred objects


Deferred objects are returned by certain methods of the Enabler API, for example by getRoot() of the navigation model. Deferred objects need to be used to define one or more callbacks and afterwards, to start the operation itself. When you start the operation, you specify whether you want to start it synchronously or asynchronously. In case the operation is started synchronously, the JavaScript processing continues only after the operation finishes, in case it is started asynchronously, it proceeds immediately. Note that the callbacks are invoked in both cases to provide results. When a callback is invoked, a result, a status, and a parameter object is passed to the callback.

Example 1: Using a deferred object to obtain the root node of the navigation model

// using the deferred object
var dfr = nm.getRoot();
var parameters = {name: "hugo"};
dfr.setFinishedCallback(getRoot_finished, parameters);
dfr.start();

// callback function
function getRoot_finished(result, status, parameters) {
    // handle result with regards to status
    if (status == 400) {
        var root = result;
        ...
    }
    // may use parameter object
    if (parameters) {
        alert(parameters.name);  // alert("hugo");
        ...
    }
}


Example 2: Starting an operation synchronously (by using the default of the start method)

// using the deferred object
var dfr = nm.getRoot();
dfr.setFinishedCallback(getRoot_finished);
dfr.start();  // respectively dfr.start(true); to explicitly specify the mode to start

// subsequent code is processed only after the 
// above operation is finished


Example 3: Starting an operation asynchronously

// using the deferred object
var dfr = nm.getRoot();
dfr.setFinishedCallback(getRoot_finished);
dfr.start(false);

// subsequent code is processed immediately

expanded Article information
collapsed Article information
Category:
Developing
Tags:
API, JavaScript, asynchronous operations

This Version: Version 2 January 24, 2010 4:39:00 PM by Anna G O'Neal  IBMer
   
expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (2)
collapsed Versions (2)
expanded Version Comparison
collapsed Version Comparison
     
Version Date Changed by               Summary of changes
This version (2) Jan 24, 2010 4:39:00 PM Anna G O'Neal  
1 Jan 24, 2010 4:22:50 PM Anna G O'Neal  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Tip: When linking to articles use the original title, not the edited title. The alias for the link can be the edited title.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • Lotus Technical Information and Education Team Blog
  • Lotus Tech Info on Twitter
  • Lotus Tech Info on Facebook
  • Lotus product forums
  • Lotus Tech Info blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use
Return to English
Arabic
Chinese Simplified
Chinese Traditional
French
German
Italian
Japanese
Korean
Portuguese
Russian
Spanish