diff options
| author | mat <github@matdoes.dev> | 2022-03-05 16:58:43 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-03-05 16:58:43 -0600 |
| commit | 5226124e477aa1c706960b7c56fafd001ce7e007 (patch) | |
| tree | c7de655848121b515117bc47f3af00bc32c39bdd /src/routes | |
| parent | cf7c8a7b343acd7c9a4b6087f9a76b2e099889d5 (diff) | |
| download | skyblock-stats-5226124e477aa1c706960b7c56fafd001ce7e007.tar.gz skyblock-stats-5226124e477aa1c706960b7c56fafd001ce7e007.tar.bz2 skyblock-stats-5226124e477aa1c706960b7c56fafd001ce7e007.zip | |
donators
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/election.svelte | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/routes/election.svelte b/src/routes/election.svelte index 7b156b6..15134b1 100644 --- a/src/routes/election.svelte +++ b/src/routes/election.svelte @@ -43,14 +43,19 @@ $: nextSpecialMayorYear = Math.ceil(((data.current?.year || data.previous.year) + 1) / 8) * 8 const specialMayors = ['Scorpius', 'Derpy', 'Jerry'] + let autoInvalidateTimeout: null | NodeJS.Timeout = null + // invalidate at the end of every minute async function autoInvalidate(first: boolean) { - if (browser && !destroyed) { + if (browser) { // don't invalidate the first time the function is called if (!first) await invalidate('') const lastUpdatedAgo = Date.now() - data.last_updated * 1000 - setTimeout(() => autoInvalidate(false), lastUpdatedAgo + 10 * 60 * 1000) + autoInvalidateTimeout = setTimeout( + () => autoInvalidate(false), + lastUpdatedAgo + 10 * 60 * 1000 + ) } } @@ -63,6 +68,7 @@ onDestroy(() => { destroyed = true + if (autoInvalidateTimeout) clearTimeout(autoInvalidateTimeout) }) </script> |
