Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


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.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: