Skip to content

Commit

Permalink
Make async locks into properties to only instantiate when used
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Claeys committed May 13, 2022
1 parent c44ce0e commit 1f7fb68
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions httpx_auth/oauth2_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,22 @@ class TokenMemoryCache:
def __init__(self):
self.tokens = {}
self.forbid_concurrent_cache_access = threading.Lock()
self.forbid_concurrent_cache_access_async = asyncio.Lock()
self._forbid_concurrent_cache_access_async = None
self.forbid_concurrent_missing_token_function_call = threading.Lock()
self.forbid_concurrent_missing_token_function_call_async = asyncio.Lock()
self._forbid_concurrent_missing_token_function_call_async = None

@property
def forbid_concurrent_cache_access_async(self):
if self._forbid_concurrent_cache_access_async is None:
self._forbid_concurrent_cache_access_async = asyncio.Lock()
return self._forbid_concurrent_cache_access_async

@property
def forbid_concurrent_missing_token_function_call_async(self):
if self._forbid_concurrent_missing_token_function_call_async is None:
self._forbid_concurrent_missing_token_function_call_async = asyncio.Lock()
return self._forbid_concurrent_missing_token_function_call_async


def _add_bearer_token(self, key: str, token: str):
"""
Expand Down

0 comments on commit 1f7fb68

Please sign in to comment.