Hacker News new | ask | show | jobs
by cliff 4972 days ago
On the homepage, there is an example of an incrementing counter. Is this actually an atomic operation, or if two users hit the button at the same time, will it potentially only increase the count by 1?
1 comments

Great catch! This should properly be implemented using leases:

    lease.acquire('count')
    local count = storage.count or 0
    storage.count = count + 1
    lease.release('count')
    return {count=count}
We skipped the lease just for simplicity's sake, but if you need that kind of protection, that's why we implemented leases.