https://github.com/matryer/resync
sync.Once with Reset()
https://github.com/matryer/resync
Last synced: 9 months ago
JSON representation
sync.Once with Reset()
- Host: GitHub
- URL: https://github.com/matryer/resync
- Owner: matryer
- License: mit
- Created: 2015-03-30T13:48:33.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-10-06T11:01:20.000Z (over 5 years ago)
- Last Synced: 2025-03-24T15:11:15.944Z (10 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 74
- Watchers: 3
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# resync
`sync.Once` with `Reset()`
* See [sync.Once](http://golang.org/pkg/sync/#Once)
Rather than adding this project as a dependency, consider [dropping](https://github.com/matryer/drop) this file into your project.
## Example
The following example examines how `resync.Once` could be used in a HTTP server situation.
```go
// 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
}
```