How to stop perform request for example with audio or video stream by some condition like callback or similar like it doing in cURL?
Asked
Active
Viewed 95 times
-4
-
2Possible duplicate of http://stackoverflow.com/questions/6807590/how-to-stop-a-goroutine. Also read this article: https://blog.golang.org/pipelines – Endre Simo Aug 02 '16 at 13:43
-
2Also possible duplicate / related: 1. [cancel a blocking operation in Go](http://stackoverflow.com/questions/28240133/cancel-a-blocking-operation-in-go); 2. [Goroutine execution inside an http handler](http://stackoverflow.com/questions/31116870/goroutine-execution-inside-an-http-handler); 3. [Is there anyway to close client request in golang/gin?](http://stackoverflow.com/questions/32470792/is-there-anyway-to-close-client-request-in-golang-gin) – icza Aug 02 '16 at 13:54
1 Answers
1
I believe what you are looking for is the context package. There is a good blog article on golang.org explaining how to use it here.
The gist of it is, you create a context object, and pass it to your goroutine that is performing streaming. In your caller goroutine you can cancel the context or set a timeout. In the streaming goroutine you have to check for context.Done()
and act accordingly.
If the action is actually an http request that you want to cancel, you can do it at the transport level (when you get a message on context.Done()
)

Dean Elbaz
- 2,310
- 17
- 17