Skip to content

Instantly share code, notes, and snippets.

@jensarps
Created February 4, 2010 23:53
Show Gist options
  • Save jensarps/295287 to your computer and use it in GitHub Desktop.
Save jensarps/295287 to your computer and use it in GitHub Desktop.
Micro Promise implementation
dojox.Promise = function(){
return {
emit: function(data){ // stub function
},
then: function(doneHandler,errHandler){
var promise = new dojox.Promise();
dojo.connect(this, 'emit', function(data){
if(doneHandler && !(data instanceof Error)){
var res = doneHandler(data);
promise.emit(res);
}
if(errHandler && (data instanceof Error)){
errHandler(data);
promise.emit(data);
}
});
return promise;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment