Sometimes it's useful to use an index in the database as a lock:
events = db['events']
items = events['items']
with events['lock']:
new_uuid = str(uuid4())
if len(items) > 0:
items[-1]['next_uuid'] = new_uuid
items.append({'data': 'abc', 'next_uuid': None})
db['events']['lock'] would just be a bool and the request would wait for the bool to become false, change it to true, and then return, waiting for a followup request to set it back to false.
Alternatively, this could be generalized to a type of request that waits for a value to change.
Sometimes it's useful to use an index in the database as a lock:
db['events']['lock']would just be abooland the request would wait for the bool to become false, change it to true, and then return, waiting for a followup request to set it back to false.Alternatively, this could be generalized to a type of request that waits for a value to change.