As it will be made obvious soon, I am a golang n00b.
I have some go code that starts goroutines based on an event channel. Say it starts 2 goroutines because we receive 2 events of type START.
The goroutine is started with an uri as parameter, which gives us something unique about it.
Later we receive one event of type STOP.
How can I stop the goroutine that was started with the same uri ?
for {
select {
case event := <-eventCh:
if event.Entry != nil {
switch event.Action {
case foo.START:
log.Println("uri: ", event.Entry.URI)
go func(c chan []byte, u string) error{
//awesome goroutine code
}(myChan, event.Entry.URI)
case foo.STOP:
log.Println("uri: ", event.Entry.URI)
//I'd like to terminate the goroutine that matches event.Entry.URI
}
}
}
}