Skip to content

Instantly share code, notes, and snippets.

@ui2code
Created November 27, 2014 05:30
Show Gist options
  • Select an option

  • Save ui2code/b1c48a583f9bf797a4e8 to your computer and use it in GitHub Desktop.

Select an option

Save ui2code/b1c48a583f9bf797a4e8 to your computer and use it in GitHub Desktop.
Promise - Dojo 1.8.4
require(["dojo/Deferred", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Deferred, dom, on){
function asyncProcess(msg){
var deferred = new Deferred();
dom.byId("output").innerHTML += "<br/>I'm running...";
setTimeout(function(){
deferred.progress("halfway");
}, 1000);
setTimeout(function(){
deferred.resolve("finished");
}, 1500);
setTimeout(function(){
deferred.reject("ooops");
}, 2000);
return deferred.promise;
}
on(dom.byId("startButton"), "click", function(){
var process = asyncProcess();
process.then(function(results){
dom.byId("output").innerHTML += "<br/>I'm finished, and the result was: " + results;
}, function(err){
dom.byId("output").innerHTML += "<br/>I errored out with: " + err;
}, function(progress){
dom.byId("output").innerHTML += "<br/>I made some progress: " + progress;
});
});
});
var usuario = Ext.create('Usuario', {
nome : 'Hemerson',
senha : 'teste'
});
console.log( usuario );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment