Untitled
unknown
plain_text
a year ago
814 B
15
Indexable
def unlock(self, key: str) -> str | None:
# If the key doesn't exist in the database and isn't currently locked, it's an invalid request.
if key not in self.db and key not in self.locks:
return "invalid_request"
# If the key exists but is not locked, return None.
if key not in self.locks:
return None
# Handle the lock release
self.locks.pop(key)
# If there are users waiting in the queue for this key, assign the lock to the next user.
if key in self.lock_queues and self.lock_queues[key]:
next_user = self.lock_queues[key].popleft()
self.locks[key] = next_user
return "released"
# If there are no more users in the queue, clean up the queue.
if key in self.lock_queues:
del self.lock_queues[key]
return "released"
Editor is loading...
Leave a Comment