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