forked from sombr/go-container-roundrobin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
67 lines (53 loc) · 1.87 KB
/
interface.go
File metadata and controls
67 lines (53 loc) · 1.87 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -----------------------------------------------------------------
* P u b l i c D o m a i n / F O S
* Copyright (C)2025 Muhammad H. Hosseinpour,
* Copyright (C)2025 Dídimo Grimaldo T.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* A generic interface to the RingQueue implementations (plain & safe)
* offered by this GO module.
*-----------------------------------------------------------------*/
package roundrobin
import (
"fmt"
"io"
"time"
)
/* ----------------------------------------------------------------
* G l o b a l s
*-----------------------------------------------------------------*/
const ( // what happens when Push() on a full circular buffer
WhenFullError WhenFull = iota
WhenFullOverwrite
)
const ( // what happens when Pop() on an empty circular buffer
WhenEmptyError WhenEmpty = iota
WhenEmptyBlock
)
var ( // module errors
ErrFullQueue = fmt.Errorf("ring buffer is full")
ErrEmptyQueue = fmt.Errorf("ring buffer is empty")
ErrClosed = fmt.Errorf("ring buffer is closed")
ErrBadDeadline = fmt.Errorf("deadline only possible for WhenEmptyBlock")
)
/* ----------------------------------------------------------------
* I n t e r f a c e s
*-----------------------------------------------------------------*/
type IRingQueue[T any] interface {
fmt.Stringer
io.Closer
SetPopDeadline(t time.Time) error
SetWhenFull(a WhenFull) IRingQueue[T]
SetOnClose(callback OnCloseCallback[T]) IRingQueue[T]
Size() int
Cap() int
Push(element T) (newLen int, err error)
Pop() (element T, newLen int, err error)
Peek() (element T, len int, err error)
Reset()
}
/* ----------------------------------------------------------------
* P u b l i c T y p e s
*-----------------------------------------------------------------*/
type WhenEmpty int
type WhenFull int
type OnCloseCallback[T any] func(data T)