Skip to content

Instantly share code, notes, and snippets.

@Fasteroid
Created October 17, 2025 18:43
Show Gist options
  • Select an option

  • Save Fasteroid/feb80c7a8e43824e32a4d45260ccc0d8 to your computer and use it in GitHub Desktop.

Select an option

Save Fasteroid/feb80c7a8e43824e32a4d45260ccc0d8 to your computer and use it in GitHub Desktop.
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