Skip to content

Commit

Permalink
exclusive Async locker
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy committed Aug 13, 2024
1 parent a24f5e3 commit 50f90d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion aiowialon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,18 @@ def timeout(self, timeout: float) -> None:

@property
def session_lock(self) -> Callable:
"""Decorator to set exclusive session access for long critical operations"""
"""
Decorator to set exclusive session access for long critical operations
>>> # Example
>>> from aiowialon import Wialon
>>> wialon = Wialon()
>>>
>>> @wialon.avl_event_handler()
>>> @wialon.session_lock # exclusive session lock for callback's frame
>>> async def unit_event(event: AvlEvent):
>>> await wialon.core_search_item(id=event.data.i, flags=1)
"""

return self.__exclusive_session_lock.lock

Expand Down
2 changes: 1 addition & 1 deletion examples/aiolock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def register_avl_events(session_login):
@wialon.avl_event_handler()
@wialon.session_lock # exclusive session lock for callback's frame
async def unit_event(event: AvlEvent):
await wialon.core_search_item(id=734455, flags=1)
await wialon.core_search_item(id=event.data.i, flags=1)
print("Handler got event:", event)
for i in range(5):
print("Waiting exclusive operation", i, "item:", event.data.i)
Expand Down

0 comments on commit 50f90d1

Please sign in to comment.