utils.ts -> Throttler.ts
This commit is contained in:
		
							parent
							
								
									20de548763
								
							
						
					
					
						commit
						c8a38cdd83
					
				
							
								
								
									
										17
									
								
								frontend/src/Throttler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								frontend/src/Throttler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| export class Throttler { | ||||
|     private hasBeenCalledWithinTime = false; | ||||
|     private lastCallFunc: (() => any) | null = null; | ||||
| 
 | ||||
|     public constructor(private minimumTimeBetweenCall: number) {} | ||||
| 
 | ||||
|     public call(func: () => any) { | ||||
|         this.lastCallFunc = func; | ||||
|         if (this.hasBeenCalledWithinTime) return; | ||||
|         this.hasBeenCalledWithinTime = true; | ||||
|         func(); | ||||
|         setTimeout(() => { | ||||
|             this.hasBeenCalledWithinTime = false; | ||||
|             if (this.lastCallFunc) this.lastCallFunc(); | ||||
|         }, this.minimumTimeBetweenCall); | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user