|
|
|
|
|
by never_inline
210 days ago
|
|
Here's a use case - singleton instantiation on first request, where instantiation itself requires an async call (eg: to DB or external service). _lock = asyncio.Lock()
_instance = None
def get_singleton():
if _instance:
return _instance
async with _lock:
if not _instance:
_instance = await costly_function()
return _instance
How do you suggest to replace this? |
|