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

counter.gno

0.61 Kb · 34 lines
 1package launchpad
 2
 3// Counter manages unique incrementing IDs.
 4type Counter struct {
 5	id int64
 6}
 7
 8// NewCounter creates a new Counter starting at zero.
 9//
10// Returns:
11//   - counter: counter initialized with current ID zero.
12func NewCounter() *Counter {
13	return &Counter{
14		id: 0,
15	}
16}
17
18// Next increments the counter and returns the next unique ID.
19//
20// Returns:
21//   - id: incremented counter value.
22func (c *Counter) Next() int64 {
23	c.id++
24
25	return c.id
26}
27
28// Get returns the current counter ID without incrementing it.
29//
30// Returns:
31//   - id: current counter value.
32func (c *Counter) Get() int64 {
33	return c.id
34}