Skip to content

Commit

Permalink
Merge pull request #24 from Joshuaalbert/f23
Browse files Browse the repository at this point in the history
* Do #23
  • Loading branch information
Joshuaalbert authored Oct 16, 2024
2 parents 424be8b + 19006b1 commit d1299ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fair_async_rlock/fair_async_rlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def is_owner(self, task=None):
task = asyncio.current_task()
return self._owner == task

def locked(self) -> bool:
return self._owner is not None

async def acquire(self):
"""Acquire the lock."""
me = asyncio.current_task()
Expand Down
10 changes: 10 additions & 0 deletions fair_async_rlock/tests/test_fair_async_rlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,13 @@ async def task3():
t3 = asyncio.create_task(task3())

await asyncio.gather(t1, t2, t3)

@pytest.mark.asyncio
def test_locked():
lock = FairAsyncRLock()
assert not lock.locked()
async def task():
async with lock:
assert lock.locked()
asyncio.run(task())
assert not lock.locked()

0 comments on commit d1299ec

Please sign in to comment.