mirror of
				https://github.com/Brandon-Rozek/website.git
				synced 2025-10-30 21:41:12 +00:00 
			
		
		
		
	Added callable check
This commit is contained in:
		
							parent
							
								
									6b750e4c1d
								
							
						
					
					
						commit
						68e4211310
					
				
					 1 changed files with 4 additions and 0 deletions
				
			
		|  | @ -16,6 +16,8 @@ class Application: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.callbacks = [] |         self.callbacks = [] | ||||||
|     def subscribe(self, func): |     def subscribe(self, func): | ||||||
|  |         if not callable(func): | ||||||
|  |             raise ValueError("Argument func must be callable.") | ||||||
|         self.callbacks.append(func) |         self.callbacks.append(func) | ||||||
|         return func |         return func | ||||||
|     def emit(self, message): |     def emit(self, message): | ||||||
|  | @ -57,6 +59,8 @@ class Application: | ||||||
|         self.callbacks = defaultdict(list) |         self.callbacks = defaultdict(list) | ||||||
|     def on(self, event, func=None): |     def on(self, event, func=None): | ||||||
|         def subscribe(func): |         def subscribe(func): | ||||||
|  |             if not callable(func): | ||||||
|  |                 raise ValueError("Argument func must be callable.") | ||||||
|             self.callbacks[event].append(func) |             self.callbacks[event].append(func) | ||||||
|             return func |             return func | ||||||
|         if func is None: |         if func is None: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue