Skip to content

Commit 00249d2

Browse files
committed
Release resources when stopped
1 parent 19f9a6d commit 00249d2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bufferflow_timed.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type BufferflowTimed struct {
1111
Port string
1212
Output chan []byte
1313
Input chan string
14+
ticker *time.Ticker
1415
}
1516

1617
var (
@@ -28,9 +29,8 @@ func (b *BufferflowTimed) Init() {
2829
}()
2930

3031
go func() {
31-
c := time.Tick(16 * time.Millisecond)
32-
log.Println(bufferedOutput)
33-
for _ = range c {
32+
b.ticker = time.NewTicker(16 * time.Millisecond)
33+
for _ = range b.ticker.C {
3434
m := SpPortMessage{bufferedOutput}
3535
buf, _ := json.Marshal(m)
3636
b.Output <- []byte(buf)
@@ -93,4 +93,6 @@ func (b *BufferflowTimed) IsBufferGloballySendingBackIncomingData() bool {
9393
}
9494

9595
func (b *BufferflowTimed) Close() {
96+
b.ticker.Stop()
97+
close(b.Input)
9698
}

0 commit comments

Comments
 (0)