Steven Olmsted![]()
Y.AsyncCommand instances are designed to be one time use only. This plugin adds a clone method to help facilitate running the same command many times.
If you haven't seen gallery-async, start there: http://yuilibrary.com/gallery/show/Async
It provides convenient syntax so you may not ever need to deal with AsyncCommand instances directly. For example, you could pass the same command function several times into runAll or runQueue instead of creating an AsyncCommand instance and cloning it.
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2012.06.20-20-07'
}).use('gallery-async-command-clone', function(Y) {
var value = 5,
asyncCommand = new Y.AsyncCommand({
fn: function (success) {
Y.later(1000, null, function () {
value += value;
success();
});
}
}).plug(Y.Plugin.AsyncCommandClone);
Y.Async.runAll([
asyncCommand.clone.clone(),
asyncCommand.clone.clone(),
asyncCommand.clone.clone(),
asyncCommand.clone.clone(),
asyncCommand.clone.clone()
]).on('complete', function () {
alert(value);
});
});
© 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