buf

package module
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package buf provides `BufferedChan` that is more efficient than `chan []interface{}`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedChan

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

BufferedChan behaves like a `chan []interface{}` (See thread safety for restrictions), but is most efficient as it uses internally a channel of []interface{}. This reduces the number of reads and writes to the channel. Instead of having one write and one read for each value for a regular channel, there are one write and one read for each `bufferSize` value. Thread safety:

  • `BufferedChan.Put` cannot be called concurrently.
  • `BufferedChan.Get` cannot be called concurrently.
  • `BufferedChan.Put` can be called while another goroutine calls `BufferedChan.Get`.

func NewBufferedChan

func NewBufferedChan(ctx context.Context, chanSize int, bufferSize int) *BufferedChan

NewBufferedChan creates a new instance of `BufferedChan`. `ctx` can be used to cancel all Put and Get operations.

func (*BufferedChan) Close

func (c *BufferedChan) Close()

Close flushes and closes the channel

func (*BufferedChan) Get

func (c *BufferedChan) Get() (interface{}, bool)

Get gets the value and returns false when the channel is closed and all

values were read.

Cannot be called concurrently.

func (*BufferedChan) Put

func (c *BufferedChan) Put(value interface{}) bool

Put puts a new value into c. Cannot be called concurrently. Returns false when BufferedChan is cancelled.

func (*BufferedChan) WaitForValue

func (c *BufferedChan) WaitForValue() bool

WaitForValue waits until a value is available for Get or until Close is called or when the context is Done Returns true if a value is available, false otherwise

Jump to

Keyboard shortcuts

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