util

package
v0.0.0-...-9f1eba6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2017 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package striplines strips runs of consecutive empty lines from an output stream. http://stackoverflow.com/questions/28353313/strip-consecutive-empty-lines-in-a-golang-writer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(path string) bool

//////////////////////////////////////////////////////////////////////////////

Types

type Striplines

type Striplines struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

Striplines wraps an output stream, stripping runs of consecutive empty lines. You must call Flush before the output stream will be complete. Implements io.WriteCloser, Writer, Closer.

func NewStriplines

func NewStriplines() *Striplines

func (*Striplines) Close

func (w *Striplines) Close() error

Close flushes the last of the output into the underlying writer.

func (*Striplines) HasContent

func (w *Striplines) HasContent() bool

func (*Striplines) Lines

func (w *Striplines) Lines() int

func (*Striplines) Write

func (w *Striplines) Write(p []byte) (int, error)

type Throttle

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

A Throttle permits throttling of a goroutine by calling the Throttle method repeatedly.

func NewThrottle

func NewThrottle(r float64, dt time.Duration) *Throttle

NewThrottle creates a new Throttle with a throttle value r and a minimum allocated run time slice of dt:

r == 0: "empty" throttle; the goroutine is always sleeping
r == 1: full throttle; the goroutine is never sleeping

A value of r == 0.6 throttles a goroutine such that it runs approx. 60% of the time, and sleeps approx. 40% of the time. Values of r < 0 or r > 1 are clamped down to values between 0 and 1. Values of dt < 0 are set to 0.

func (*Throttle) Throttle

func (p *Throttle) Throttle()

Throttle calls time.Sleep such that over time the ratio tr/ts between accumulated run (tr) and sleep times (ts) approximates the value 1/(1-r) where r is the throttle value. Throttle returns immediately (w/o sleeping) if less than tm ns have passed since the last call to Throttle.

func (*Throttle) Triggered

func (p *Throttle) Triggered() bool

is Throttle even triggered

type TimeoutListener

type TimeoutListener struct {
	*net.TCPListener
}

//////////////////////////////////////////////////////////////////////////////

func NewTimeoutListener

func NewTimeoutListener(inner *net.TCPListener) *TimeoutListener

//////////////////////////////////////////////////////////////////////////////

func (*TimeoutListener) Accept

func (ln *TimeoutListener) Accept() (c net.Conn, err error)

//////////////////////////////////////////////////////////////////////////////

Jump to

Keyboard shortcuts

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