unbounded

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package unbounded holds a non-blocking FIFO buffer (but not lockfree) that will grow and shrink to accomidate entries. We can only guarentee FIFO with a single receiver. With multiple receivers, you are getting close to FIFO order.

Usage is simple:

b := Buffer{} // or b := Buffer{}

// This will never block.
b.Push(item)

// Gets the next item from the buffer, but returns !ok if the buffer is empty.
v, ok := b.Pop()
if !ok {
	fmt.Println("nothing in the buffer")
}

// This will block until an item becomes available.
v = b.Pull()

// This will loop until b.Close() is called.
for v = range b.Next() {
	fmt.Println(%v, v)
}

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 the Buffer should not have a memory bound.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a FIFO queue. The queue can grow to infinite size and pushing an item will never fail. This value must never be copied once created (in other words, make it a pointer value if shared across func/method boundaries).

func (*Buffer) Close

func (b *Buffer) Close()

Close closes the output channel used in Next() calls. This is only needed if you are using .Next() and not Pop() or Pull().

func (*Buffer) Next

func (b *Buffer) Next() chan interface{}

Next pulls an item from the Buffer until Close() is called. This is nice for for/range loops, but is slightly slower than Pull() and requires a goroutine per Next() call. Note: Do not use Pop/Pull() and Next() together, use one or the other.

func (*Buffer) Pop

func (b *Buffer) Pop() (val interface{}, ok bool)

Pop pops an item from the Buffer. If an item cannot be returned, it returns ok == false. Note: Do not use Pop() and Next() together, use one or the other. Note: It is safe to use Pop() and Pull() together.

func (*Buffer) Pull

func (b *Buffer) Pull() interface{}

Pull will block until it can pop an item from the buffer. Note: Do not use Pull() and Next() together, use one or the other. Note: It is safe to use Pop() and Pull() together.

func (*Buffer) Push

func (b *Buffer) Push(item interface{})

Push pushes an item onto the Buffer.

Directories

Path Synopsis
experimental
unbounded/custom_sleep_atomic
Package custom_sleep_atomic holds a non-blocking circular buffer (but not lockfree) that will grow and shrink to size requirements.
Package custom_sleep_atomic holds a non-blocking circular buffer (but not lockfree) that will grow and shrink to size requirements.
internal
spin
Package spin provides objects for assisting with sleeping while waiting for an action to become available.
Package spin provides objects for assisting with sleeping while waiting for an action to become available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL