Documentation
¶
Overview ¶
Package custom_sleep_atomic holds a non-blocking circular buffer (but not lockfree) that will grow and shrink to size requirements.
Usage is simple:
b := Buffer{} // or b := Buffer{Max: Unbounded} if setting a custom max buffer size // This will only block if the Buffer has reached its max size. if !b.Push(item) { fmt.Println("buffer has reached its max size") } v, ok := b.Pop() if !ok { fmt.Println("nothing in the buffer") } b.Force(item) // This will push an item on and will block if we have reached the max buffer size v = b.Pull() // This will block until an item becomes available.
Type customization note:
You can make this package compiler safe by replacing interface{} with your own custom type and importing the library containing that type. We highly suggest this.
Index ¶
Constants ¶
View Source
const Unbounded = -1
Unbounded indicates that the Queue should have no memory bounds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct { // Max is the maximum size the Buffer can grow to. Use Unbounded if // you wish to grow the buffer to any size. By default this will grow to 1k items. Max int // contains filtered or unexported fields }
Buffer provides a FIFO circular buffer that can grow and shrink as required. Buffer must not be copied after creation (which means use a pointer if passing between functions).
func (*Buffer) Force ¶
func (c *Buffer) Force(item interface{})
Force will push the item onto the buffer and blocks until the operation completes.
func (*Buffer) Pop ¶
Pop returns the next value off the circular buffer. If the buffer is empty ok will be false.