sync.Once with Reset()
Go
Switch branches/tags
Nothing to show
Clone or download
Latest commit d39c09a Dec 12, 2016
Permalink
Failed to load latest commit information.
.gitignore Initial commit Mar 30, 2015
LICENSE Create LICENSE Jun 30, 2016
README.md Update README.md Dec 11, 2016
once.go tweaks Mar 30, 2015
once_test.go added Once (twice really) Mar 30, 2015

README.md

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
}