dispatch/vendor/github.com/matryer/resync
2017-04-18 03:02:51 +02:00
..
LICENSE Upgrade server dependencies, manage them with govendor 2017-04-18 03:02:51 +02:00
once.go Switch from Godep to go vendoring 2016-03-01 01:51:26 +01:00
README.md Upgrade server dependencies, manage them with govendor 2017-04-18 03:02:51 +02:00

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
}