mirror of
https://github.com/PretendoNetwork/nex-go.git
synced 2025-04-02 11:02:14 -04:00
24 lines
513 B
Go
24 lines
513 B
Go
package nex
|
|
|
|
// Counter represents an incremental counter
|
|
type Counter struct {
|
|
value uint32
|
|
}
|
|
|
|
// Value returns the counters current value
|
|
func (counter Counter) Value() uint32 {
|
|
return counter.value
|
|
}
|
|
|
|
// Increment increments the counter by 1 and returns the value
|
|
func (counter *Counter) Increment() uint32 {
|
|
counter.value++
|
|
return counter.Value()
|
|
}
|
|
|
|
// NewCounter returns a new Counter, with a starting number
|
|
func NewCounter(start uint32) *Counter {
|
|
counter := &Counter{value: start}
|
|
|
|
return counter
|
|
}
|