Documentation ¶
Overview ¶
Package count counts with concurrency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunCountHandler ¶
func RunHelloWorldHandler ¶
Types ¶
type AtomicCounter ¶
type AtomicCounter uint64
AtomicCounter implements Counter with atomic package. Go has only int64 atomic variable. This uses math.Float64frombits package for the floating point number corresponding the IEEE 754 binary representation
func (*AtomicCounter) Add ¶
func (c *AtomicCounter) Add(delta float64)
Add ignores the non-integer part of delta.
func (*AtomicCounter) Get ¶
func (c *AtomicCounter) Get() float64
type AtomicIntCounter ¶
type AtomicIntCounter int64
AtomicIntCounter implements Counter with atomic package. Go has only int64 atomic variable. This truncates float value into integer.
func (*AtomicIntCounter) Add ¶
func (c *AtomicIntCounter) Add(delta float64)
Add ignores the non-integer part of delta.
func (*AtomicIntCounter) Get ¶
func (c *AtomicIntCounter) Get() float64
type ChannelCounter ¶
type ChannelCounter struct {
// contains filtered or unexported fields
}
ChannelCounter counts through channels.
func NewChannelCounter ¶
func NewChannelCounter(buf int) *ChannelCounter
func (*ChannelCounter) Add ¶
func (c *ChannelCounter) Add(delta float64)
func (*ChannelCounter) Close ¶
func (c *ChannelCounter) Close()
func (*ChannelCounter) Done ¶
func (c *ChannelCounter) Done()
func (*ChannelCounter) Get ¶
func (c *ChannelCounter) Get() float64
func (*ChannelCounter) Run ¶
func (c *ChannelCounter) Run()
type Counter ¶
type Counter interface { // Get returns the current count. Get() float64 // Add adds the delta value to the counter. Add(delta float64) }
Counter is an interface for counting. It contains counting data as long as a type implements all the methods in the interface.
type MutexCounter ¶
type MutexCounter struct {
// contains filtered or unexported fields
}
MutexCounter implements Counter with sync.Mutex.
func (*MutexCounter) Add ¶
func (c *MutexCounter) Add(delta float64)
func (*MutexCounter) Get ¶
func (c *MutexCounter) Get() float64
type NaiveCounter ¶
type NaiveCounter float64
NaiveCounter counts in a naive way. Do not use this with concurrency. It will cause race conditions. This is not thread-safe.
func (*NaiveCounter) Add ¶
func (c *NaiveCounter) Add(delta float64)
func (*NaiveCounter) Get ¶
func (c *NaiveCounter) Get() float64
type RWMutexCounter ¶
type RWMutexCounter struct {
// contains filtered or unexported fields
}
RWMutexCounter implements Counter with sync.RWMutex.
func (*RWMutexCounter) Add ¶
func (c *RWMutexCounter) Add(delta float64)
func (*RWMutexCounter) Get ¶
func (c *RWMutexCounter) Get() float64