mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-31 01:54:37 +00:00 
			
		
		
		
	
		
			
	
	
		
			24 lines
		
	
	
		
			370 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
		
		
			
		
	
	
			24 lines
		
	
	
		
			370 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
|   | import 'dart:async'; | ||
|  | 
 | ||
|  | class Throttler { | ||
|  |   Throttler({ | ||
|  |     this.duration = const Duration(milliseconds: 1000), | ||
|  |   }); | ||
|  | 
 | ||
|  |   final Duration duration; | ||
|  |   Timer? _timer; | ||
|  | 
 | ||
|  |   void call(Function callback) { | ||
|  |     if (_timer?.isActive ?? false) return; | ||
|  | 
 | ||
|  |     _timer = Timer(duration, () { | ||
|  |       callback(); | ||
|  |     }); | ||
|  |   } | ||
|  | 
 | ||
|  |   void dispose() { | ||
|  |     _timer?.cancel(); | ||
|  |     _timer = null; | ||
|  |   } | ||
|  | } |