github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/staticcheck/sa1015/testdata/src/example.com/CheckLeakyTimeTick/CheckLeakyTimeTick.go (about)

     1  package pkg
     2  
     3  import "time"
     4  
     5  func fn1() {
     6  	for range time.Tick(0) {
     7  		println("")
     8  	}
     9  }
    10  
    11  func fn2() {
    12  	for range time.Tick(0) { //@ diag(`leaks the underlying ticker`)
    13  		println("")
    14  		if true {
    15  			break
    16  		}
    17  	}
    18  }
    19  
    20  func fn3() {
    21  	for range time.Tick(0) { //@ diag(`leaks the underlying ticker`)
    22  		println("")
    23  		if true {
    24  			return
    25  		}
    26  	}
    27  }
    28  
    29  func fn4() {
    30  	go func() {
    31  		for range time.Tick(0) {
    32  			println("")
    33  		}
    34  	}()
    35  }
    36  
    37  func fn5() {
    38  	if false {
    39  		panic("foo")
    40  	}
    41  	for range time.Tick(0) {
    42  		println("")
    43  	}
    44  }
    45  
    46  
    47  type T struct{}
    48  
    49  func (t *T) foo() {
    50  	for range time.Tick(0) {
    51  		println("")
    52  	}
    53  }
    54  
    55  func (t T) bar() {
    56  	for range time.Tick(0) {
    57  		println("")
    58  	}
    59  }