limiter kills previous goroutines if used 2 or more the same time
type Workers struct {
Scanner *limiter.ConcurrencyLimiter
Reader *limiter.ConcurrencyLimiter
Remover *limiter.ConcurrencyLimiter
Storage sync.Map
}
worker.Scanner.Execute(func() {
err := readDir(path+"/"+e.Name(), worker, threadId, false)
if err != nil {
fmt.Println(err)
}
})
worker.Reader stopping worker.Scanner once started.
worker.Reader.Execute(func() {
for {
data, ok := worker.Storage.Load(threadId)
if ok {
fmt.Println("buffer", threadId, "contains", len(data.([]int)), "elements")
fmt.Println("scanner threads in progress", worker.Scanner.GetNumInProgress())
fmt.Println("reader threads in progress", worker.Reader.GetNumInProgress())
} else {
fmt.Println("buffer", threadId, "is empty")
}
time.Sleep(time.Second * 5)
}
})
does it panic ? since if it does, the go routine will crash the process i believe.
otherwise, i am not sure i understand the question
No panic, no errors, new go routines of the first limiter does not spawn
Отправлено из мобильной Почты Mail.ru
четверг, 6 апреля 2023 г. в 21:26 +0300 от @.*** @.***>:
does it panic ? since if it does, the go routine will crash the process i believe. — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread. Message ID: <korovkin/limiter/issues/24/1499456607 @ github . com>
I believe it just stops to spawn when the second one runs and working I’ve seen in in logs
Отправлено из мобильной Почты Mail.ru
четверг, 6 апреля 2023 г. в 21:26 +0300 от @.*** @.***>:
otherwise, i am not sure i understand the question — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread. Message ID: <korovkin/limiter/issues/24/1499457131 @ github . com>
perhaps you could share the whole end2end example with the main function so i could run it and understand it more ?
`func main() { l1 := *limiter.NewConcurrencyLimiter(10) l2 := *limiter.NewConcurrencyLimiter(10)
l1.Execute(func() {
for {
fmt.Println("l1 is alive")
time.Sleep(time.Second * 5)
l2.Execute(func() {
for {
fmt.Println("l2 is alive")
time.Sleep(time.Second * 5)
}
})
}
})
l1.WaitAndClose()
l2.WaitAndClose()
}`
Run it and wait some time, you will see only l2 is alive after some minutes
@evgenyrelap i tried the code above, it's running here -
it seems to work https://github.com/korovkin/limiter/pull/25
so what is the question
the usage pattern is not exactly as intended ... but still works, i believe.