diode

package
v0.0.0-...-758c02f Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alerter

type Alerter func(missed int)

type Writer

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

Writer is a io.Writer wrapper that uses a diode to make Write lock-free, non-blocking and thread safe.

func NewWriter

func NewWriter(w io.Writer, size int, poolInterval time.Duration, f Alerter) *Writer

NewWriter creates a writer wrapping w with a many-to-one diode in order to never block the producers and drop writes if the underlying writer can't keep up with the flow of data.

Use a diode.Writer when

wr := diode.NewWriter(w, 1000, 0, func(missed int) {
    log.Printf("Dropped %d writes", missed)
})
wr.Write([]byte("Hello, World!"))

If pollInterval is greater than 0, a poller is used otherwise a waiter is used.

See code.cloudfoundry.org/go-diodes for more info on diode.

func (*Writer) Close

func (dw *Writer) Close() error

Close releases the diode poller and call Close on the wrapped writer if io.Closer is implemented.

func (*Writer) Write

func (dw *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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