Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created April 30, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatiasq/0f584b9154a48745a6b4 to your computer and use it in GitHub Desktop.
Save amatiasq/0f584b9154a48745a6b4 to your computer and use it in GitHub Desktop.
(function() {
function Deferred() {
if (window.Promise) {
var that = this;
this.promise = new Promise(function(resolve, reject) {
that._resolve = resolve;
that._reject = reject;
});
}
}
Deferred.prototype.resolve = function(value) {
if (this._resolve)
this._resolve(value);
};
Deferred.prototype.reject = function(reason) {
if (this._reject)
this._reject(reason);
};
window.Deferred = Deferred;
})();
function async() {
var def = new Deferred();
def.resolve();
return def.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment