Created
August 13, 2020 22:44
-
-
Save ahmedsakr/1f88d2ebf9fab2736ab285a753aff489 to your computer and use it in GitHub Desktop.
A naive approach to implementing the Ordered Server Counter
This file contains hidden or 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
import material from 'materialize-css/dist/js/materialize'; | |
let count = 0; | |
// Server simulation | |
async function processCommand() { | |
count += 1; | |
return count; | |
} | |
// Network delay simulation | |
async function serverDelay() { | |
return new Promise(resolve => setTimeout(resolve, parseInt(Math.random() * 500))); | |
} | |
window.addEventListener('load', () => { | |
document.getElementById("genToast").addEventListener('click', async () => { | |
await serverDelay(); | |
let number = await processCommand() | |
await serverDelay(); | |
material.toast({ | |
html: `<span style="font-size: 48px; padding: 2rem;">#${number}</span>`, | |
displayLength: 1000 | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment