mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
simplified enqueue
This commit is contained in:
@@ -111,15 +111,15 @@ func handleSignals(cancel context.CancelFunc) {
|
||||
cancel()
|
||||
}
|
||||
|
||||
// enqueue things into the specified channel or log if full
|
||||
// enqueue things into the specified channel or return an error if full.
|
||||
func enqueue[T any](queue chan T) func(t T) error {
|
||||
return func(t T) error {
|
||||
select {
|
||||
case queue <- t:
|
||||
default:
|
||||
log.Printf("channel is full, dropping %v", t)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("channel is full, dropping %v", t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user