Last active
January 30, 2019 22:13
-
-
Save weizman/8f5434d884648a704e831c20bda93282 to your computer and use it in GitHub Desktop.
demonstration of what can be done inside an `unload`/`beforeunload` listener
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
window.addEventListener('unload', (e) => { | |
function sleep(delay) { | |
const start = new Date().getTime(); | |
while (new Date().getTime() < start + delay); | |
} | |
// unloading won't finish until 10 full seconds pass! | |
sleep(10000); | |
setTimeout(() => { | |
// this part would be ignored since unloading will already | |
// finish by now, thus it won't wait for this async call | |
sleep(10000); | |
}, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment