Skip to content

Commit

Permalink
Add a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
radazen committed Oct 20, 2023
1 parent a59b27c commit 6d1d44e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/dataloaders/generator/dataloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func (d *Dataloader[TKey, TResult]) addKeyToBatch(key TKey, jsonKey string) (*ba
}

b := actual.(*batch[TKey, TResult])

// Prevent lock contention within a batch by allowing only the first maxBatchSize callers
// to obtain the lock.
numAssigned := atomic.AddInt32(&b.numAssigned, 1)
if numAssigned > int32(d.maxBatchSize) {
atomic.CompareAndSwapInt32(&d.currentBatchID, currentID, currentID+1)
Expand Down

0 comments on commit 6d1d44e

Please sign in to comment.