Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

counter.gno

0.67 Kb · 28 lines
 1package staker
 2
 3type Counter struct {
 4	id int64
 5}
 6
 7// NewCounter creates a counter initialized before the first allocated identifier.
 8//
 9// Returns:
10//   - *Counter: counter whose current identifier is zero.
11func NewCounter() *Counter {
12	return &Counter{id: 0}
13}
14
15// Get returns the counter's current identifier without incrementing it.
16//
17// Returns:
18//   - int64: most recently allocated identifier, or zero for a new counter.
19func (c *Counter) Get() int64 { return c.id }
20
21// Next increments the counter and returns the newly allocated identifier.
22//
23// Returns:
24//   - int64: next identifier after incrementing the counter by one.
25func (c *Counter) Next() int64 {
26	c.id++
27	return c.id
28}