diff --git a/README.md b/README.md index 8e9384b..1abc418 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dataloader.go b/dataloader.go index e691824..0f8ac5b 100644 --- a/dataloader.go +++ b/dataloader.go @@ -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