Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created July 3, 2014 21:01
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 bradoyler/e37522622ce30cc0ebc1 to your computer and use it in GitHub Desktop.
Save bradoyler/e37522622ce30cc0ebc1 to your computer and use it in GitHub Desktop.
lame attempt at promise queue
function Promise() {
this.callbackQ = [],
this.errorQ = [],
this.then = function(callback, error){
this.callbackQ.push(callback);
this.errorQ.push(error);
},
this.resolve = function(context) {
this.callbackQ.forEach(function(func){
if(typeof context== 'object' || typeof context=='function') {
func.call(context);
}
else{
func();
}
});
this.callbackQ=[];
}
this.reject = function() {
this.errorQ.forEach(function(func){
func();
});
this.errorQ=[];
}
}
var a = new Promise();
a.then(function(){
console.log('1st Promise');
});
a.then(function(){
console.log('2st Promise');
});
a.resolve();
a.resolve();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment