从链表中取出超时的数据,可选每次取出最多多少数据
(max int)
| 61 | |
| 62 | // 从链表中取出超时的数据,可选每次取出最多多少数据 |
| 63 | func (this *LocalStruct) GetTimeoutData(max int) []LocalRetryStruct { |
| 64 | this.lock.Lock() |
| 65 | defer this.lock.Unlock() |
| 66 | currentTime := time.Now().Unix() |
| 67 | index := 0 |
| 68 | var tables []LocalRetryStruct |
| 69 | j := 0 |
| 70 | for i := 0; i < len(this.items); i++ { |
| 71 | if currentTime-this.items[i].v.Time < 5 { |
| 72 | break |
| 73 | } |
| 74 | if index > max { |
| 75 | break |
| 76 | } |
| 77 | index++ |
| 78 | j = i |
| 79 | tables = append(tables, LocalRetryStruct{this.items[i].v, this.items[i].index}) |
| 80 | } |
| 81 | if len(tables) > 0 { |
| 82 | this.items = append(this.items[j+1:]) |
| 83 | } |
| 84 | return tables |
| 85 | } |