Changeset 59 in code for trunk/ring.go
- Timestamp:
- Feb 17, 2020, 3:09:35 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ring.go
r57 r59 18 18 } 19 19 20 // NewRing creates a new ring buffer. 20 21 func NewRing(capacity int) *Ring { 21 22 return &Ring{ … … 25 26 } 26 27 28 // Produce appends a new message to the ring buffer. 27 29 func (r *Ring) Produce(msg *irc.Message) { 28 30 r.lock.Lock() … … 43 45 } 44 46 45 func (r *Ring) Consumer(seq *uint64) (*RingConsumer, <-chan struct{}) { 47 // NewConsumer creates a new ring buffer consumer. 48 // 49 // If seq is nil, the consumer will get messages starting from the last 50 // producer message. If seq is non-nil, the consumer will get messages starting 51 // from the specified history sequence number (see RingConsumer.Close). 52 // 53 // The returned channel yields a value each time the consumer has a new message 54 // available. Consume should be called to drain the consumer. 55 // 56 // The consumer can only be used from a single goroutine. 57 func (r *Ring) NewConsumer(seq *uint64) (*RingConsumer, <-chan struct{}) { 46 58 consumer := &RingConsumer{ 47 59 ring: r, … … 64 76 } 65 77 78 // RingConsumer is a ring buffer consumer. 66 79 type RingConsumer struct { 67 80 ring *Ring … … 79 92 } 80 93 94 // Peek returns the next pending message if any without consuming it. A nil 95 // message is returned if no message is available. 81 96 func (rc *RingConsumer) Peek() *irc.Message { 82 97 if rc.closed { … … 103 118 } 104 119 120 // Consume consumes and returns the next pending message. A nil message is 121 // returned if no message is available. 105 122 func (rc *RingConsumer) Consume() *irc.Message { 106 123 msg := rc.Peek() … … 111 128 } 112 129 130 // Close stops consuming messages. The consumer channel will be closed. The 131 // current history sequence number is returned. It can be provided later as an 132 // argument to Ring.NewConsumer to resume the message stream. 113 133 func (rc *RingConsumer) Close() uint64 { 114 134 rc.ring.lock.Lock()
Note:
See TracChangeset
for help on using the changeset viewer.