mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
wip: fix batch
This commit is contained in:
parent
81d4d84868
commit
738ddd94b5
@ -38,24 +38,6 @@ func Batch[T any](ctx context.Context, ch <-chan T, batchSize int, fn func([]T))
|
||||
fn(batch)
|
||||
batch = make([]T, 0, batchSize) // reset
|
||||
}
|
||||
default:
|
||||
if len(batch) > 0 { // partial
|
||||
fmt.Println("<< 5")
|
||||
fn(batch)
|
||||
batch = make([]T, 0, batchSize) // reset
|
||||
} else { // empty
|
||||
// wait for more
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case v, ok := <-ch:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
batch = append(batch, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user