Untitled
unknown
plain_text
a year ago
850 B
8
Indexable
def unlock(self, key: str) -> str | None:
# First, check if the key exists in the database at all.
if key not in self.db and key not in self.locks:
return "invalid_request"
# If there is no lock on the key but it exists in the database, return None.
if key not in self.locks:
return None
# Handle the lock release.
current_lock = self.locks.pop(key, None)
# If there are users waiting in the lock queue.
if self.lock_queues.get(key):
next_user = self.lock_queues[key].popleft()
self.locks[key] = next_user # Transfer the lock to the next user
return "released" # Lock was released and transferred to the next user
# If the lock is released without any queue.
return "released" # This case means the lock was released from the current user with no one to transfer
Editor is loading...
Leave a Comment