support nil receivers
This commit is contained in:
@@ -18,22 +18,28 @@ type RecordQueue struct {
|
||||
l *list.List
|
||||
}
|
||||
|
||||
// Push inserts the Record at the back of the queue. If pushing a nil Record then it's a no-op.
|
||||
func (rq *RecordQueue) Push(r Record) {
|
||||
if rq.l == nil {
|
||||
rq.l = list.New()
|
||||
}
|
||||
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if rq == nil {
|
||||
// This would cause a panic anyway so, we panic with a more meaningful message
|
||||
panic("Push to nil RecordQueue")
|
||||
}
|
||||
|
||||
if rq.l == nil {
|
||||
rq.l = list.New()
|
||||
}
|
||||
|
||||
rq.l.PushBack(r)
|
||||
}
|
||||
|
||||
// Pop removes and returns the first element of the list as the first return value. If the list is
|
||||
// empty returns falso on the 2nd return value, true otherwise.
|
||||
func (rq *RecordQueue) Pop() (Record, bool) {
|
||||
if rq.l == nil {
|
||||
if rq == nil || rq.l == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -48,7 +54,7 @@ func (rq *RecordQueue) Pop() (Record, bool) {
|
||||
}
|
||||
|
||||
func (rq *RecordQueue) Len() int {
|
||||
if rq.l == nil {
|
||||
if rq == nil || rq.l == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user