feat: a lot of a lot
This commit is contained in:
		
							
								
								
									
										0
									
								
								decorators/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								decorators/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										19
									
								
								decorators/async_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								decorators/async_utils.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
import asyncio
 | 
			
		||||
from functools import wraps
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def async_to_sync(func):
 | 
			
		||||
    @wraps(func)
 | 
			
		||||
    def wrapper(*args, **kwargs):
 | 
			
		||||
        # Get the current event loop
 | 
			
		||||
        loop = asyncio.get_event_loop()
 | 
			
		||||
 | 
			
		||||
        # If there is no current event loop, create a new one
 | 
			
		||||
        if loop.is_closed():
 | 
			
		||||
            loop = asyncio.new_event_loop()
 | 
			
		||||
            asyncio.set_event_loop(loop)
 | 
			
		||||
 | 
			
		||||
        # Run the async function until complete and return the result
 | 
			
		||||
        return loop.run_until_complete(func(*args, **kwargs))
 | 
			
		||||
 | 
			
		||||
    return wrapper
 | 
			
		||||
		Reference in New Issue
	
	Block a user