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

wrap.gno

0.72 Kb · 26 lines
 1// Package wrap is version 0 of the "wrapping versions" upgrade pattern
 2// (pattern A of the exploration; see ../README.md).
 3//
 4// Nothing here knows that a successor exists. v0 keeps its own counter and
 5// stays writable forever: callers pinned to this path keep working, and keep
 6// diverging from whatever the newer version reports.
 7package wrap
 8
 9import "gno.land/p/nt/ufmt/v0"
10
11var counter int
12
13// Inc adds n to this version's own counter.
14func Inc(cur realm, n int) {
15	counter += n
16}
17
18// Get returns this version's counter. Non-crossing on purpose: a successor
19// reads it without entering this realm as a writer.
20func Get() int {
21	return counter
22}
23
24func Render(_ string) string {
25	return ufmt.Sprintf("wrap/v0: %d\n", counter)
26}