Fix possible panic on race condition

This commit is contained in:
Darren Shepherd 2021-05-10 15:06:15 -07:00
parent 97ff535abc
commit c6547ae887

View File

@ -175,11 +175,6 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.WatchRequest) (chan types.APIEvent, error) {
result := make(chan types.APIEvent, 1)
go func() {
<-apiOp.Context().Done()
close(result)
}()
result <- types.APIEvent{
Name: "local",
ResourceType: "management.cattle.io.clusters",
@ -187,5 +182,10 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
Object: s.getLocal(),
}
go func() {
<-apiOp.Context().Done()
close(result)
}()
return result, nil
}