|
1 | 1 | /*
|
2 | 2 | *
|
3 |
| - * Copyright 2022 gRPC authors. |
| 3 | + * Copyright 2023 gRPC authors. |
4 | 4 | *
|
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | * you may not use this file except in compliance with the License.
|
@@ -31,23 +31,27 @@ type ClientStateChangeSubscriberInterface interface {
|
31 | 31 | ClientStateChangeListenOnChannel(m connectivity.State)
|
32 | 32 | }
|
33 | 33 |
|
| 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. |
34 | 37 | type ClientStateChangePublisher struct {
|
35 | 38 | stateListeners []chan connectivity.State
|
36 | 39 | }
|
37 | 40 |
|
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. |
39 | 43 | func (p *ClientStateChangePublisher) Register(s ClientStateChangeSubscriberInterface) {
|
40 | 44 | p.stateListeners = append(p.stateListeners, s.GetStateChannel())
|
41 | 45 | go func() {
|
42 | 46 | for {
|
43 | 47 | state := <-s.GetStateChannel()
|
44 | 48 | s.ClientStateChangeListenOnChannel(state)
|
45 |
| - // TODO(miyoshi): goroutineメモリリークを避けるために終了処理が必要か? |
46 | 49 | }
|
47 | 50 | }()
|
48 | 51 | }
|
49 | 52 |
|
50 |
| -// ClientConn 側から呼ばれる想定 |
| 53 | +// Publish is called to publish the connectivity.State changes on ClientConn |
| 54 | +// to listeners. |
51 | 55 | func (p *ClientStateChangePublisher) Publish(m connectivity.State) {
|
52 | 56 | for _, c := range p.stateListeners {
|
53 | 57 | c <- m
|
|
0 commit comments