Skip to content

Commit 44c5cd1

Browse files
committed
ts: adopt stopper handle in poller
1 parent 3c2a109 commit 44c5cd1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/ts/db.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,18 @@ func (db *DB) PollSource(
141141
// start begins the goroutine for this poller, which will periodically request
142142
// time series data from the DataSource and store it.
143143
func (p *poller) start() (firstDone <-chan struct{}) {
144-
ch := make(chan struct{})
145-
// Poll once immediately and synchronously.
146-
bgCtx := p.AnnotateCtx(context.Background())
147-
if p.stopper.RunAsyncTask(bgCtx, "ts-poller", func(ctx context.Context) {
148-
ch := ch // goroutine-local copy
144+
ch := make(chan struct{}) // closed on completion of first poll
145+
ctx, hdl, err := p.stopper.GetHandle(
146+
p.AnnotateCtx(context.Background()), stop.TaskOpts{TaskName: "ts-poller"},
147+
)
148+
if err != nil {
149+
close(ch)
150+
return ch
151+
}
152+
go func(ctx context.Context, ch chan struct{}) {
153+
defer hdl.Activate(ctx).Release(ctx)
149154
var ticker timeutil.Timer
150-
ticker.Reset(0)
155+
ticker.Reset(0) // poll immediately
151156
defer ticker.Stop()
152157
for {
153158
select {
@@ -162,9 +167,7 @@ func (p *poller) start() (firstDone <-chan struct{}) {
162167
return
163168
}
164169
}
165-
}) != nil {
166-
close(ch)
167-
}
170+
}(ctx, ch)
168171
return ch
169172
}
170173

0 commit comments

Comments
 (0)