Created
January 23, 2022 21:37
-
-
Save mdespriee/55b42fc4dc7396b9c55686f9bf714f39 to your computer and use it in GitHub Desktop.
decorator meant to build singletons, and designed for async coroutines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def async_cache(func): | |
""" | |
decorator meant to build singletons, and designed for async coroutines | |
:param func: | |
:return: | |
""" | |
instances = {} | |
@functools.wraps(func) | |
async def wrapper(*args, **kwargs): | |
if func not in instances: | |
instances[func] = await func(*args, **kwargs) | |
return instances[func] | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment