4 ms·
Most blocking syscalls in Go cannot be terminated by any means. [1] It seems unlikely that the stdlib os API will add dozens of variants taking context.Context
by networkimprov 6y ago
Most blocking syscalls in Go cannot be terminated by any means. [1]
It seems unlikely that the stdlib os API will add dozens of variants taking context.Context. The new FS API proposal makes no mention of deadlines or contexts. [2]
[1] https://github.com/golang/go/issues/41054 https://github.com/golang/go/issues/41054
[2] https://github.com/golang/go/issues/5636#issuecomment-661926962 https://github.com/golang/go/issues/5636#issuecomment-661926...
- ohnoesjmr 6y agoAtleast file io used to spawn a thread just for that, so cancellations and deadlines were still respected
- networkimprov 6y agoYou have to be able to direct a signal to the thread blocked on the syscall to be terminated. Go has no way to obtain the Id of that thread. That's what the issue I linked above covers.
- mleonhard 6y agoHere's some Golang code that does it: https://github.com/kawasin73/gointr https://github.com/kawasin73/gointr I think you could use that technique to make blocking syscalls that take a context.Context and return early if the context becomes done.