Skip to content

Commit f76b3b6

Browse files
committed
add comment
1 parent 029f12c commit f76b3b6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/clientutil/state_polling.go renamed to internal/clientutil/connectivity_state_pubsub.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2022 gRPC authors.
3+
* Copyright 2023 gRPC authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -31,23 +31,27 @@ type ClientStateChangeSubscriberInterface interface {
3131
ClientStateChangeListenOnChannel(m connectivity.State)
3232
}
3333

34+
// ClientStateChangePublisher manages listeners. Users should use a function Register
35+
// to register a subscriber to listeners and Publish to publish the connectivity.State
36+
// changes on ClientConn to subsribers registered by using Register.
3437
type ClientStateChangePublisher struct {
3538
stateListeners []chan connectivity.State
3639
}
3740

38-
// Register is going to be called by Management Server Sides
41+
// Register registers a state channel to ClientStateChangePublisher's listeners
42+
// and waits until the connectivity.State of ClientConn change is reported.
3943
func (p *ClientStateChangePublisher) Register(s ClientStateChangeSubscriberInterface) {
4044
p.stateListeners = append(p.stateListeners, s.GetStateChannel())
4145
go func() {
4246
for {
4347
state := <-s.GetStateChannel()
4448
s.ClientStateChangeListenOnChannel(state)
45-
// TODO(miyoshi): goroutineメモリリークを避けるために終了処理が必要か?
4649
}
4750
}()
4851
}
4952

50-
// ClientConn 側から呼ばれる想定
53+
// Publish is called to publish the connectivity.State changes on ClientConn
54+
// to listeners.
5155
func (p *ClientStateChangePublisher) Publish(m connectivity.State) {
5256
for _, c := range p.stateListeners {
5357
c <- m

0 commit comments

Comments
 (0)