• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    This module has been deprecated and is no longer supported by the module author.

    Deferred (gallery-deferred) on cdn

    Last Updated: 04/13/13

    Juan Ignacio Dopazo

    YUI Contributor

    See 3 more by this user.

    Created: 08/15/11
    Last CDN Push: 10/17/12
    Build Tag: gallery-2012.10.17-20-00
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.9.1
    Free for use.

    This module includes:

    • A Y.when() function for waiting for multiple asynchronous calls
    • A series of methods for IO. All of them allow of a last parameter to be either a callback or a configuration object with an "on" property for "success" and "failure" callbacks
      • Y.io.get(url) Requires io-base
      • Y.io.post(url, data) Requires io-base
      • Y.io.postForm(url, formId) Requires io-base
      • Y.io.getJSON(url) Requires io-base,json
      • Y.io.jsonp(url) Requires io,jsonp
    • A plugin for Node called Y.Plugin.NodeDeferred with deferred versions of several asynchronous Node methods:
      • node.deferred.transition(opts) Requires transition
      • node.deferred.load(url) Requires node-load

    • Tags:
    • jdopazo
    • deferred
    • io
    • transition
    • async
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.9.1/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2012.10.17-20-00'
    }).use('io', 'gallery-deferred', function(Y) {
     
      // make multiple IO requests and deal with them when they are all completed
      Y.when(Y.io.get('foo.html'), Y.io.getJSON('bar.json')).then(function (a, b) {
        // a and b are arrays with the arguments received by deferred.resolve() in each case,
        // so the first element in each array is an EventFacade with responseText and data properties
        console.log(a[0].responseText, b[0].data);
      });
     
      // use a plugin for chaining asynchronous Node methods one after the other and not all at the same time
      var node = Y.one('#foo').plug(Y.Plugin.NodeDeferred);
      node.deferred.transition({ left: '300px' })
                   .transition({ top: '300px' })
                   .load('some-content.html')
                   .transition({ width: '420px', height: '420px', top: '30px' });
     
      // create your own deferred functions...
      Y.wait = function (ms) {
        var deferred = new Y.Deferred();
        Y.later(ms, deferred, deferred.resolve);
        return deferred.promise();
      };
      Y.wait(2000).then(function () {
        // do something 2 seconds later
      });
     
      // ... and add them to all Promises for extra fun!
      Y.Promise.prototype.wait = function () {
        return this.then(Y.wait);
      };
      Y.io.postForm('foo.php', '#someform').wait(1000).then(function () {
        // do something 1 second later of a certain IO request being completed
        // maybe hide a process indicator?
      });
    });

    Forum Posts

    Subject Author Date
    Change Log Juan Ignacio Dopazo 05/28/12
    Can haz just promises? Luke Smith 08/27/12
    Re: Can haz just promises? Juan Ignacio Dopazo 08/28/12
    deferred Java API and feedback Sebastián Gurin 08/30/12
    What is the best way to start with Promises? Marco Asbreuk 02/1/13
    Re: What is the best way to start with Promises? Alberto Santini 02/15/13
    Re: What is the best way to start with Promises? Marco Asbreuk 02/15/13

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info