Last active
May 1, 2018 21:52
-
-
Save mattcodez/149ab3e54a80322e32bb485f8bf936c3 to your computer and use it in GitHub Desktop.
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 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