Skip to content

Commit

Permalink
lock staticmethod extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
pseusys committed Nov 29, 2024
1 parent a54df18 commit 49d3bff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
24 changes: 12 additions & 12 deletions chatsky/context_storages/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def __eq__(self, other: Any) -> bool:
return super().__eq__(other)


def _lock(function: Callable[..., Awaitable[Any]]):
@wraps(function)
async def wrapped(self, *args, **kwargs):
if not self.is_concurrent:
async with self._sync_lock:
return await function(self, *args, **kwargs)
else:
return await function(self, *args, **kwargs)

return wrapped


class DBContextStorage(ABC):
_default_subscript_value: int = 3

Expand Down Expand Up @@ -111,18 +123,6 @@ def __init__(
def is_concurrent(self) -> bool:
raise NotImplementedError

@staticmethod
def _lock(function: Callable[..., Awaitable[Any]]):
@wraps(function)
async def wrapped(self, *args, **kwargs):
if not self.is_concurrent:
async with self._sync_lock:
return await function(self, *args, **kwargs)
else:
return await function(self, *args, **kwargs)

return wrapped

@classmethod
def _validate_field_name(cls, field_name: str) -> str:
if field_name not in (NameConfig._labels_field, NameConfig._requests_field, NameConfig._responses_field):
Expand Down
1 change: 0 additions & 1 deletion tests/core/test_context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from altair import Key
import pytest

from chatsky.core.context import Context, ContextError
Expand Down

0 comments on commit 49d3bff

Please sign in to comment.