tools

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetModulePath

func GetModulePath(module string) string

GetModulePath will return the source path of the given module under the github.com/uber/aresdb/subscriber. This function uses the default GOPATH/GOENV resolution to find the given module

func ToJSON

func ToJSON(data interface{}) string

ToJSON converts input to JSON format

Types

type Batcher

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

Batcher batches a sequence of tasks and send them to workers for execution asynchronously. A batch of size 2^x is flushed when either maxDelay has elapsed since the oldest task was added, or a max number of tasks have been queued.

func NewBatcher

func NewBatcher(maxBatchSize int, maxDelay time.Duration, now func() time.Time) *Batcher

NewBatcher creates and starts a batcher with no worker. User must call StartWorker before any task can be processed.

func (*Batcher) Add

func (b *Batcher) Add(task interface{}, time time.Time)

Add adds a task to the batcher for asynchronous processing.

func (*Batcher) Close

func (b *Batcher) Close()

Close signals all workers to quit and blocks until all queued tasks are processed.

func (*Batcher) StartWorker

func (b *Batcher) StartWorker(run func(chan []interface{}, *sync.WaitGroup))

StartWorker adds a worker to the batcher and runs it asynchronously. The worker func shall receive task batches from the channel, and notify the wait group when it quits.

Jump to

Keyboard shortcuts

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