Skip to content

Commit

Permalink
fix incorrect statement
Browse files Browse the repository at this point in the history
  • Loading branch information
freerkminnema authored Jan 15, 2025
1 parent a744856 commit 4942fb4
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ In its most elegant form, you can pass a simple closure to the `synchronized` fu
$ticketNumber = synchronized(fn () => Cache::increment('ticket-number'));
```

Since `Cache::increment` is not an atomic operation, you would normally run the risk of returning identical numbers on parallel server requests. But when we wrap it in `synchronized`, we ensure the `Cache::increment` never runs in parallel.

## How does it work?

Internally, `synchronized` generates an *Atomic Lock Key* (which is simply a hashed string) based on the location of and variables in the callable. This is just like how the ✨magic✨ `once` function works.
Expand Down Expand Up @@ -72,4 +70,4 @@ use App\Models\TicketDispenser;

$dispenser = TicketDispenser::find(Request::get('ticket-dispenser-id'));
$ticket = synchronized(fn () => $dispenser->nextTicket(), $dispenser);
```
```

0 comments on commit 4942fb4

Please sign in to comment.