forked from influxdata/influxdb-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
43 lines (36 loc) · 780 Bytes
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2020 InfluxData, Inc. All rights reserved.
// Use of this source code is governed by MIT
// license that can be found in the LICENSE file.
package influxdb2
import "container/list"
type queue struct {
list *list.List
limit int
}
func newQueue(limit int) *queue {
return &queue{list: list.New(), limit: limit}
}
func (q *queue) push(batch *batch) bool {
overWrite := false
if q.list.Len() == q.limit {
q.pop()
overWrite = true
}
q.list.PushBack(batch)
return overWrite
}
func (q *queue) pop() *batch {
el := q.list.Front()
if el != nil {
q.list.Remove(el)
return el.Value.(*batch)
}
return nil
}
func (q *queue) first() *batch {
el := q.list.Front()
return el.Value.(*batch)
}
func (q *queue) isEmpty() bool {
return q.list.Len() == 0
}