> > My previous questions were: How can I cancel execution of goToSleep() > function? How can I break it? > > Maybe you want something like this? https://play.golang.org/p/2dKbVMxBjaJ
context <https://blog.golang.org/context> is the standard way to be able to cancel one or more of goroutines, such as those working together to handle a particular request. The goroutines need to cooperate with this mechanism, by noticing that the cancellation signal has been sent and then finishing. This is done inside interruptibleSleep in the above example. Many library functions now accept a context so that they can be terminated in this way. Also, if the point of this is to give up after a timeout, the context itself can carry a deadline, which simplifies things: https://play.golang.org/p/TPJYrCcnq8c -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/46f94c36-c632-4e08-859e-61171c4381b8%40googlegroups.com.