There is a third-party library that does some doIt () work for a very long time. You can run the execution of this function in a separate gorutin, but how to stop its implementation ahead of time?

func doIt() { // очень долго работает } func main() { result := make(chan int) go func() { result <- doIt() }{} fmt.Println(<-result) } 
  • Add a question with your code. - Mothership

1 answer 1

If the creators of the library did not give you the opportunity to transfer a context or at least just a channel to the gorutin, then no. Technically, gorutin has identifiers, but they are hidden from "userspace".