counter

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package counter contains varias counter tools

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChildParallelCounter

type ChildParallelCounter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ChildParallelCounter child of ParallelCounter

func (*ChildParallelCounter) Count

func (c *ChildParallelCounter) Count() (r int64)

Count count 1

func (*ChildParallelCounter) CountN

func (c *ChildParallelCounter) CountN(n int64) (r int64)

CountN count n

func (*ChildParallelCounter) Get

func (c *ChildParallelCounter) Get() int64

Get get current count

type Counter

type Counter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Counter int64 counter

Example
counter := NewCounter()
counter.Count()
counter.CountN(10)
counter.Get() // get current count
Output:

func NewCounter

func NewCounter() *Counter

NewCounter create Counter from 0

func NewCounterFromN

func NewCounterFromN(n int64) *Counter

NewCounterFromN create Counter from custom number

func (*Counter) Count

func (c *Counter) Count() int64

Count increse and return the result

func (*Counter) CountN

func (c *Counter) CountN(n int64) int64

CountN increse N and return the result

func (*Counter) Get

func (c *Counter) Get() int64

Get return current counter's number

func (*Counter) GetSpeed

func (c *Counter) GetSpeed() (r float64)

GetSpeed return increasing speed from lastest invoke `GetSpeed`

func (*Counter) Set

func (c *Counter) Set(n int64)

Set overwrite the counter's number

type Int64CounterItf

type Int64CounterItf interface {
	Count() int64
	CountN(n int64) int64
}

Int64CounterItf counter for int64

type ParallelCounter

type ParallelCounter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ParallelCounter parallel count with child counter

func NewParallelCounter

func NewParallelCounter(quoteStep, rotatePoint int64) (*ParallelCounter, error)

NewParallelCounter get new parallel counter

func NewParallelCounterFromN

func NewParallelCounterFromN(n, quoteStep, rotatePoint int64) (*ParallelCounter, error)

NewParallelCounterFromN get new parallel counter

func (*ParallelCounter) GetChild

func (c *ParallelCounter) GetChild() *ChildParallelCounter

GetChild create new child

func (*ParallelCounter) GetQuote

func (c *ParallelCounter) GetQuote(step int64) (from, to int64)

GetQuote child request new quote from parent

type RotateCounter

type RotateCounter struct {
	gutils.Mutex
	// contains filtered or unexported fields
}

RotateCounter rotate counter

Example
counter, err := NewRotateCounter(10)
if err != nil {
	panic(err)
}

counter.Count()    // 1
counter.CountN(10) // 1
Output:

func NewRotateCounter

func NewRotateCounter(rotatePoint int64) (*RotateCounter, error)

NewRotateCounter create new RotateCounter with threshold from 0

func NewRotateCounterFromN

func NewRotateCounterFromN(n, rotatePoint int64) (*RotateCounter, error)

NewRotateCounterFromN create new RotateCounter with threshold from N

func NewRotateCounterFromNWithCtx

func NewRotateCounterFromNWithCtx(ctx context.Context, n, rotatePoint int64) (*RotateCounter, error)

NewRotateCounterFromNWithCtx create new RotateCounter with threshold from N

func NewRotateCounterWithCtx

func NewRotateCounterWithCtx(ctx context.Context, rotatePoint int64) (*RotateCounter, error)

NewRotateCounterWithCtx create new RotateCounter with threshold from 0

func (*RotateCounter) Close

func (c *RotateCounter) Close()

Close stop rorate runner

func (*RotateCounter) Count

func (c *RotateCounter) Count() int64

Count increse and return the result

func (*RotateCounter) CountN

func (c *RotateCounter) CountN(n int64) (r int64)

CountN increse N and return the result

func (*RotateCounter) Get

func (c *RotateCounter) Get() int64

Get return current counter's number

type Uint32Counter

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

Uint32Counter uint32 counter

func NewUint32Counter

func NewUint32Counter() *Uint32Counter

NewUint32Counter return new Uint32Counter from 0

func NewUint32CounterFromN

func NewUint32CounterFromN(n uint32) *Uint32Counter

NewUint32CounterFromN return new Uint32Counter from n

func (*Uint32Counter) Count

func (c *Uint32Counter) Count() uint32

Count increse and return the result

func (*Uint32Counter) CountN

func (c *Uint32Counter) CountN(n uint32) uint32

CountN increse N and return the result

func (*Uint32Counter) Get

func (c *Uint32Counter) Get() uint32

Get return current counter's number

func (*Uint32Counter) Set

func (c *Uint32Counter) Set(n uint32)

Set overwrite the counter's number

Jump to

Keyboard shortcuts

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