resync

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 2 Imported by: 0

README

resync

sync.Once with Reset()

Rather than adding this project as a dependency, consider dropping this file into your project.

Example

The following example examines how resync.Once could be used in a HTTP server situation.

// use it just like sync.Once
var once resync.Once

// handle a web request
func handleRequest(w http.ResponseWriter, r *http.Request) {
	once.Do(func(){
		// load templates or something
	})
	// TODO: respond
}

// handle some request that indicates things have changed
func handleResetRequest(w http.ResponseWriter, r *http.Request) {
	once.Reset() // call Reset to cause initialisation to happen again above
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Once

type Once struct {
	// contains filtered or unexported fields
}

Once is an object that will perform exactly one action until Reset is called. See http://golang.org/pkg/sync/#Once

func (*Once) Do

func (o *Once) Do(f func())

Do simulates sync.Once.Do by executing the specified function only once, until Reset is called. See http://golang.org/pkg/sync/#Once

func (*Once) Reset

func (o *Once) Reset()

Reset indicates that the next call to Do should actually be called once again.

Jump to

Keyboard shortcuts

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