Created
July 3, 2014 21:01
-
-
Save bradoyler/e37522622ce30cc0ebc1 to your computer and use it in GitHub Desktop.
lame attempt at promise queue
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
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