Skip to content

Commit

Permalink
add todoruleid testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosQuildu committed Apr 11, 2024
1 parent b1a0e5b commit 03d98ac
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion go/hanging-goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
)

func main() {
req5_FP(1)
req6(1, false)
fmt.Println("Result: ", result)
fmt.Println("Goroutines (must be 1 for FPs):", runtime.NumGoroutine())
}
Expand Down Expand Up @@ -152,6 +152,32 @@ func req5_FP(timeout time.Duration) {
}
}

func req6(timeout time.Duration, doclose bool) {
ch := make(chan string)
tick := time.Tick(100 * time.Millisecond)
quit := time.After(2 * time.Second)
// todoruleid: hanging-goroutine
go func() {
newData := test()
ch <- newData // block
}()
for {
select {
case <-tick:
fmt.Print("|")
case <-quit:
if doclose {
result = <- ch
}
fmt.Println("\nquit")
return
default:
fmt.Print(".")
time.Sleep(50 * time.Millisecond)
}
}
}


func test() string {
time.Sleep(time.Second * 2)
Expand Down

0 comments on commit 03d98ac

Please sign in to comment.