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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Playground

gnomod.toml

module = "gno.land/r/nym-moultest123/x/daily/ringbufferdemo/v0"
gno = "0.9"

[addpkg]
  creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv"
  height = 186411
  max_deposit = "5000000ugnot"

render_example_test.gno

package ringbufferdemo

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// # Ring Buffer
	//
	// A fixed-capacity FIFO that overwrites its oldest entry, demoing the [`p/moul/x/daily/ringbuffer`](/p/nym-moultest123/x/daily/ringbuffer/v0) library.
	//
	// Capacity **4**, pushing 6 entries:
	//
	// | push | evicted | contents (oldest → newest) |
	// |---|---|---|
	// | `alpha` | — | `alpha` |
	// | `bravo` | — | `alpha bravo` |
	// | `charlie` | — | `alpha bravo charlie` |
	// | `delta` | — | `alpha bravo charlie delta` |
	// | `echo` | `alpha` | `bravo charlie delta echo` |
	// | `foxtrot` | `bravo` | `charlie delta echo foxtrot` |
	//
	// > The buffer never grows: once full, each push costs the oldest entry. On chain that bound is the point — an unbounded queue is an unbounded storage bill.
}

ringbufferdemo.gno

// Package ringbufferdemo is a small gnoweb demo of the fixed-capacity FIFO
// provided by the [p/moul/x/daily/ringbuffer](/p/nym-moultest123/x/daily/ringbuffer/v0)
// library: it pushes more entries than the buffer can hold and shows what
// survives, plus what each overflowing push evicted.
//
// It contains no buffer logic of its own. Stateless, so Render is deterministic.
package ringbufferdemo

import (
	"strconv"
	"strings"

	"gno.land/p/nym-moultest123/x/daily/ringbuffer/v0"
)

const capacity = 4

var feed = []string{"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"}

// Render renders the demo for gnoweb.
func Render(path string) string {
	var b strings.Builder
	b.WriteString("# Ring Buffer\n\n")
	b.WriteString("A fixed-capacity FIFO that overwrites its oldest entry, demoing the ")
	b.WriteString("[`p/moul/x/daily/ringbuffer`](/p/nym-moultest123/x/daily/ringbuffer/v0) library.\n\n")
	b.WriteString("Capacity **")
	b.WriteString(strconv.Itoa(capacity))
	b.WriteString("**, pushing ")
	b.WriteString(strconv.Itoa(len(feed)))
	b.WriteString(" entries:\n\n")
	b.WriteString("| push | evicted | contents (oldest → newest) |\n|---|---|---|\n")

	r := ringbuffer.New(capacity)
	for _, v := range feed {
		ev, dropped := r.Push(v)
		b.WriteString("| `")
		b.WriteString(v)
		b.WriteString("` | ")
		if dropped {
			b.WriteString("`" + ev + "`")
		} else {
			b.WriteString("—")
		}
		b.WriteString(" | `")
		b.WriteString(strings.Join(r.Slice(), " "))
		b.WriteString("` |\n")
	}

	b.WriteString("\n> The buffer never grows: once full, each push costs the oldest entry. ")
	b.WriteString("On chain that bound is the point — an unbounded queue is an unbounded storage bill.\n")
	return b.String()
}