File tree 1 file changed +4
-12
lines changed
1 file changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -120,17 +120,17 @@ type listener struct {
120
120
// the last value waiting to be published to the channel
121
121
lastValue * DataEvent
122
122
123
- // used for initialization
124
- startedOnce sync.Once
125
123
// channel for signaling the loop to read a new value
126
124
ping chan struct {}
127
125
}
128
126
129
127
func newListener (channel chan DataEvent ) * listener {
130
- return & listener {
128
+ l := & listener {
131
129
ping : make (chan struct {}, 1 ),
132
130
channel : channel ,
133
131
}
132
+ go l .startLoop ()
133
+ return l
134
134
}
135
135
136
136
// publish sets the publisher's lastValue and starts the
@@ -139,12 +139,6 @@ func (r *listener) publish(data *DataEvent) {
139
139
r .lastValueLock .Lock ()
140
140
r .lastValue = data
141
141
r .lastValueLock .Unlock ()
142
-
143
- r .startedOnce .Do (func () {
144
- r .ping = make (chan struct {}, 1 )
145
- go r .startLoop ()
146
- })
147
-
148
142
select {
149
143
case r .ping <- struct {}{}: // signals the startLoop that it has to read the value
150
144
default :
@@ -166,7 +160,5 @@ func (r *listener) startLoop() {
166
160
}
167
161
168
162
func (r * listener ) close () {
169
- if r .ping != nil {
170
- close (r .ping )
171
- }
163
+ close (r .ping )
172
164
}
You can’t perform that action at this time.
0 commit comments