using slices.IndexFunc (#13834)

This commit is contained in:
cui
2024-04-02 04:04:40 +08:00
committed by GitHub
parent 53fdd2d062
commit 9df20e616c

View File

@@ -20,6 +20,7 @@ package event
import ( import (
"errors" "errors"
"reflect" "reflect"
"slices"
"sync" "sync"
) )
@@ -219,12 +220,9 @@ type caseList []reflect.SelectCase
// find returns the index of a case containing the given channel. // find returns the index of a case containing the given channel.
func (cs caseList) find(channel interface{}) int { func (cs caseList) find(channel interface{}) int {
for i, cas := range cs { return slices.IndexFunc(cs, func(selectCase reflect.SelectCase) bool {
if cas.Chan.Interface() == channel { return selectCase.Chan.Interface() == channel
return i })
}
}
return -1
} }
// delete removes the given case from cs. // delete removes the given case from cs.