Skip to content

Commit 586ea60

Browse files
Maxim ClaeysMaxim Claeys
authored andcommitted
Make async locks into properties to only instantiate when used
1 parent 09af02c commit 586ea60

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

httpx_auth/oauth2_tokens.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,22 @@ class TokenMemoryCache:
4747
def __init__(self):
4848
self.tokens = {}
4949
self.forbid_concurrent_cache_access = threading.Lock()
50-
self.forbid_concurrent_cache_access_async = asyncio.Lock()
50+
self._forbid_concurrent_cache_access_async = None
5151
self.forbid_concurrent_missing_token_function_call = threading.Lock()
52-
self.forbid_concurrent_missing_token_function_call_async = asyncio.Lock()
52+
self._forbid_concurrent_missing_token_function_call_async = None
53+
54+
@property
55+
def forbid_concurrent_cache_access_async(self):
56+
if self._forbid_concurrent_cache_access_async is None:
57+
self._forbid_concurrent_cache_access_async = asyncio.Lock()
58+
return self._forbid_concurrent_cache_access_async
59+
60+
@property
61+
def forbid_concurrent_missing_token_function_call_async(self):
62+
if self._forbid_concurrent_missing_token_function_call_async is None:
63+
self._forbid_concurrent_missing_token_function_call_async = asyncio.Lock()
64+
return self._forbid_concurrent_missing_token_function_call_async
65+
5366

5467
def _add_bearer_token(self, key: str, token: str):
5568
"""

0 commit comments

Comments
 (0)