Is it a right usage calling SetReadDeadline in another routine?


In most examples, SetReadDeadline is called before calling net.Conn.Read().

In my program, to intterupt my net.Conn.Read(), I call net.Conn.SetReadDeadline(time.Now()) in another thread/routine. Is it a right way?



As the documentation states:

SetReadDeadline sets the deadline for future Read calls
and any currently-blocked Read call.
A zero value for t means Read will not time out.

The only way you can call SetReadDeadline for a blocked read call is from another goroutine, so this is ok.

Answered By – Burak Serdar

Answer Checked By – Pedro (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.