Perhaps just read the deadline in the lock, then do the rest outside the
lock:
func (s *SimplePeerConn) Read(b []byte) (n int, err error) {
s.deadlineLock.RLock()
deadline := s.readDeadline
s.deadlineLock.RUnlock()
ctx := context.Background()
if !deadline.IsZero() {
dctx, cancel :=
I have the following function:
func (s *SimplePeerConn) Read(b []byte) (n int, err error) {
ctx := context.Background()
var maybeCancelFn context.CancelFunc
func() {
s.deadlineLock.RLock()
defer s.deadlineLock.RUnlock()
if !s.readDeadline.IsZero() {
ctx, maybeCancelFn = con