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

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

v0 source pure

Package once provides utilities for one-time execution patterns. It extends the concept of sync.Once with error handl...

Readme View source

gno.land/p/moul/once/v0

One-time execution patterns.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

Package once provides utilities for one-time execution patterns. It extends the concept of sync.Once with error handling and panic options.

Variables 1

Functions 1

func New

1func New() *Once
source

New creates a new Once instance

Types 1

type Once

struct
1type Once struct {
2	done    bool
3	err     error
4	paniced bool
5	value   any // stores the result of the execution
6}
source

Once represents a one-time execution guard

Methods on Once

func Do

method on Once
1func (o *Once) Do(fn func())
source

Do executes fn only once and returns nil on subsequent calls

func DoErr

method on Once
1func (o *Once) DoErr(fn func() error) error
source

DoErr executes fn only once and returns the same error on subsequent calls

func DoOrPanic

method on Once
1func (o *Once) DoOrPanic(fn func())
source

DoOrPanic executes fn only once and panics on subsequent calls

func DoValue

method on Once
1func (o *Once) DoValue(fn func() any) any
source

DoValue executes fn only once and returns its value, subsequent calls return the cached value

func DoValueErr

method on Once
1func (o *Once) DoValueErr(fn func() (any, error)) (any, error)
source

DoValueErr executes fn only once and returns its value and error Subsequent calls return the cached value and error

func Error

method on Once
1func (o *Once) Error() error
source

Error returns the error from the last execution if any

func IsDone

method on Once
1func (o *Once) IsDone() bool
source

IsDone returns whether the Once has been executed

func Reset

method on Once
1func (o *Once) Reset()
source

Reset resets the Once instance to its initial state This is mainly useful for testing purposes

func Value

method on Once
1func (o *Once) Value() (any, error)
source

Value returns the stored value and an error if not executed yet

Dependencies

Imports 1

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/once/v0

Imported by indexer

Source Files 4