once

package
v0.0.0-...-90c9d3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 1 Imported by: 0

Documentation

Overview

This package provides a single function, Do, to run a function exactly once, usually used as part of initialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(f func())

Do is the the only exported piece of the package. For one-time initialization that is not done during init, wrap the initialization in a niladic function f() and call

Do(f)

If multiple processes call Do(f) simultaneously with the same f argument, only one will call f, and the others will block until f finishes running.

Since a func() expression typically evaluates to a differerent function value each time it is evaluated, it is incorrect to pass such values to Do. For example,

func f(x int) {
	Do(func() { fmt.Println(x) })
}

behaves the same as

func f(x int) {
	fmt.Println(x)
}

because the func() expression in the first creates a new func each time f runs, and each of those funcs is run once.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL