Created
October 17, 2025 18:43
-
-
Save Fasteroid/feb80c7a8e43824e32a4d45260ccc0d8 to your computer and use it in GitHub Desktop.
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
| export class Fire { | |
| private timeout: number = -1; | |
| private callbacks: (() => void)[] = []; | |
| public refreshDuration( time: number ){ | |
| window.clearTimeout( this.timeout ); | |
| this.timeout = window.setTimeout( () => this.burnout(), time ) | |
| } | |
| private burnout(){ | |
| for( let cb of this.callbacks ) { | |
| try { | |
| cb(); | |
| } | |
| catch(e){ | |
| console.error(e) | |
| } | |
| } | |
| this.callbacks = []; | |
| this.timeout = -1; | |
| } | |
| public onBurnout( fn: () => void ) { | |
| this.callbacks.push(fn) | |
| } | |
| public get burning() { return this.timeout !== -1 } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment