Skip to content

Instantly share code, notes, and snippets.

@kucukkanat
Created January 16, 2018 08:38
Show Gist options
  • Save kucukkanat/343db99345664900f4395b7b57570d90 to your computer and use it in GitHub Desktop.
Save kucukkanat/343db99345664900f4395b7b57570d90 to your computer and use it in GitHub Desktop.
Manual implementation of Promise
function Promise(fn) {
var callback = null;
this.then = function(cb) {
callback = cb;
};
function resolve(value) {
// force callback to be called in the next
// iteration of the event loop, giving
// callback a chance to be set by then()
setTimeout(function() {
callback(value);
}, 1);
}
fn(resolve);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment