cancel a blocking operation in Go

时光怂恿深爱的人放手 提交于 2019-11-26 18:00:53

You can't stop a goroutine from the "outside". The goroutine has to support some kind of termination signalling (most often a channel). But if it does not, you can't force it or kill it.

If you can't do anything about the 3rd party lib you're using, the most that you could do is run it in a different process (in a different application started by your go app) which you can kill, but that is just ugly and too cumbersome.

I don't think you can do anything. In Go you can't stop a goroutine from outside. If you can't fix this library and you think it could block forever, then write new one that you would be able to control.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!