Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limiter kills previous goroutines if used 2 or more the same time #24

Open
evgenyrelap opened this issue Apr 6, 2023 · 7 comments
Open

Comments

@evgenyrelap
Copy link

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)
	}
})
@korovkin
Copy link
Owner

korovkin commented Apr 6, 2023

does it panic ?
since if it does, the go routine will crash the process i believe.

@korovkin
Copy link
Owner

korovkin commented Apr 6, 2023

otherwise, i am not sure i understand the question

@evgenyrelap
Copy link
Author

evgenyrelap commented Apr 6, 2023 via email

@evgenyrelap
Copy link
Author

evgenyrelap commented Apr 6, 2023 via email

@korovkin
Copy link
Owner

korovkin commented Apr 6, 2023

perhaps you could share the whole end2end example with the main function so i could run it and understand it more ?

@evgenyrelap
Copy link
Author

`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

@korovkin
Copy link
Owner

korovkin commented Apr 7, 2023

@evgenyrelap i tried the code above, it's running here -

it seems to work
#25

so what is the question

the usage pattern is not exactly as intended ... but still works, i believe.

@korovkin korovkin mentioned this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants