Created
February 4, 2010 23:53
-
-
Save jensarps/295287 to your computer and use it in GitHub Desktop.
Micro Promise implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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