← Lesson
One Writer Per Record
Joeven
Run
Reset
Python loads on first run
LOCKS = {} def write(role, customer_id, name): owner = LOCKS.get(customer_id) if owner is None: LOCKS[customer_id] = role return {"ok": True, "name": name, "owner": role} if owner != role: return {"error": "locked", "owner": owner, "role": role} return {"ok": True, "name": name, "owner": owner, "again": True} print(write("billing", "c1", "refund")) print(write("loyalty", "c1", "credit")) print(write("billing", "c1", "email")) print(write("loyalty", "c2", "credit"))
Run to execute this in your browser. Nothing is sent to a server.