Skip to content

Commit

Permalink
add read dealine reduce use ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
soyum2222 committed Feb 6, 2021
1 parent 60e311c commit 63c00ce
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,50 @@ loop:
} else {
tick.Reset(time.Duration(remainTime) * time.Nanosecond)
}
}

} else {
if tick != nil {

if tick == nil {
tick = time.NewTicker(time.Second)
} else {
tick.Reset(time.Second)
}
}
select {
case _, ok := <-s.readBlock:
if !ok {
return 0, CLOSEERROR
}
goto loop

select {
case _, ok := <-s.readBlock:
if !ok {
return 0, CLOSEERROR
case _, _ = <-s.closeChan:
if closeRet {
return 0, CLOSEERROR
}
closeRet = true
goto loop

case <-s.errorSign:
return 0, s.errorContainer.Load().(error)
case <-tick.C:
now := time.Now()
if (!s.readDeadline.IsZero() && s.readDeadline.Before(now)) || (s.deadline.Before(now) && !s.deadline.IsZero()) {
return 0, TIMEOUERROR
}
}
goto loop
} else {

case _, _ = <-s.closeChan:
if closeRet {
return 0, CLOSEERROR
}
closeRet = true
goto loop

case <-s.errorSign:
return 0, s.errorContainer.Load().(error)
case <-tick.C:
now := time.Now()
if (!s.readDeadline.IsZero() && s.readDeadline.Before(now)) || (s.deadline.Before(now) && !s.deadline.IsZero()) {
return 0, TIMEOUERROR
select {
case _, ok := <-s.readBlock:
if !ok {
return 0, CLOSEERROR
}
goto loop

case _, _ = <-s.closeChan:
if closeRet {
return 0, CLOSEERROR
}
closeRet = true
goto loop

case <-s.errorSign:
return 0, s.errorContainer.Load().(error)
}
}
goto recheck
Expand Down

0 comments on commit 63c00ce

Please sign in to comment.