Skip to content

Instantly share code, notes, and snippets.

@mattcodez
Last active May 1, 2018 21:52
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 mattcodez/149ab3e54a80322e32bb485f8bf936c3 to your computer and use it in GitHub Desktop.
Save mattcodez/149ab3e54a80322e32bb485f8bf936c3 to your computer and use it in GitHub Desktop.
function myPromise(fn){
let done = false;
let next = [];
fn(() => {
done = true;
while (next.length > 0) next.pop()();
});
return {
then: fn => {
if (done) {
fn();
}
else {
next.push(fn);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment