buffer

package
v0.0.0-...-58614dd Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Spin provides objects for assisting with sleeping while waiting for an action to become available. This is useful in preventing CPU starvation when there is nothing to do.

Index

Constants

This section is empty.

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.

type Sleeper

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

Sleeper allows sleeping for an increasing time period up to 1 second after giving up a goroutine 2^16 times. This is not thread-safe and should be thrown away once the loop the calls it is able to perform its function.

func (*Sleeper) Sleep

func (s *Sleeper) Sleep()

Sleep at minimum allows another goroutine to be scheduled and after 2^16 calls will begin to sleep from 1 nanosecond to 1 second, with each call raising the sleep time by a multiple of 10.

Jump to

Keyboard shortcuts

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