Skip to content

Commit

Permalink
chore: improve if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Aug 1, 2024
1 parent c3fc508 commit c5b4831
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ API Design
func New[K comparable, V any](loader Loader[K, V], options ...Option) Interface[K, V]

type Interface[K comparable, V any] interface {
// Go loads a single key asynchronously
Go(context.Context, K) <-chan Result[V]
// Load loads a single key
Load(context.Context, K) Result[V]
// LoadMany loads multiple keys
Expand Down
14 changes: 7 additions & 7 deletions dataloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ func (d *dataLoader[K, V]) goLoad(ctx context.Context, key K) <-chan Result[V] {
// If there are no keys in the current batch, schedule a new batch timer
d.stopSchedule = make(chan struct{})
go d.scheduleBatch(ctx, d.stopSchedule)
}

// Check if the key is in flight
if chs, ok := d.chs[key]; ok {
d.chs[key] = append(chs, ch)
d.mu.Unlock()
return ch
} else {
// Check if the key is in flight
if chs, ok := d.chs[key]; ok {
d.chs[key] = append(chs, ch)
d.mu.Unlock()
return ch
}
}

// Add the key and channel to the current batch
Expand Down

0 comments on commit c5b4831

Please sign in to comment.