4 ms·
Sure, but what if you want to shut that goroutine down later on? The best solution that I've found is to just close the connection, the .Recv() will error out
by StavrosK 14y ago
Sure, but what if you want to shut that goroutine down later on?
The best solution that I've found is to just close the connection, the .Recv() will error out immediately.
- lobster_johnson 14y agoYes, that is afaik the only way to abort a synchronous function call such as TCPConn.Read().
- burntsushi 14y agoWhat other solution would you want? You could use `SetDeadline` if you like. But closing the connection seems reasonable too. I think you're framing the problem wrong. You're not asking to shutdown a goroutine, you're asking "How do I abort from a synchronous read from a network connection that is blocked?"
- StavrosK 14y agoDon't get too hung up on that, it was the least of the problems. Closing the connection works fine, it's just a bit unorthodox. The basic structure of the problem was much more problematic to implement.