juju: github.com/juju/juju/utils/stringforwarder Index | Files

package stringforwarder

import "github.com/juju/juju/utils/stringforwarder"

Index

Package Files

stringforwarder.go

type StringForwarder Uses

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

StringForwarder is a goroutine-safe type that pipes messages from the its Forward() method, sending them to callback. The send will not be blocked by the callback, but will instead discard messages if there is an incomplete callback in progress. The number of discarded messages is tracked and returned when the forwarder is stopped.

func New Uses

func New(callback func(string)) *StringForwarder

New returns a new StringForwarder that sends messages to the callback, function, dropping messages if the receiver has not yet consumed the last message.

func (*StringForwarder) Forward Uses

func (f *StringForwarder) Forward(msg string)

Forward sends the message to be processed by the callback function, discarding the message if another message is currently being processed. The number of discarded messages is recorded for reporting by the Stop method.

Forward is safe to call from multiple goroutines at once. Note that if this StringForwarder was created with a nil callback, all messages will be discarded.

func (*StringForwarder) Stop Uses

func (f *StringForwarder) Stop() uint64

Stop cleans up the goroutine running behind StringForwarder and returns the count of discarded messages. Stop is thread-safe and may be called multiple times - after the first time, it simply returns the current discard count.

Package stringforwarder imports 1 packages (graph) and is imported by 17 packages. Updated 2016-07-19. Refresh now. Tools for package owners.