Skip to content

Instantly share code, notes, and snippets.

@jensarps
Created Feb 4, 2010
Embed
What would you like to do?
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