Unvendor resync

This commit is contained in:
Ken-Håvard Lieng 2017-07-03 07:39:10 +02:00
parent 0a96ebb428
commit 8a62af5a73
4 changed files with 0 additions and 94 deletions

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016 Mat Ryer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,29 +0,0 @@
# 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
}
```

View File

@ -1,38 +0,0 @@
package resync
import (
"sync"
"sync/atomic"
)
// Once is an object that will perform exactly one action
// until Reset is called.
// See http://golang.org/pkg/sync/#Once
type Once struct {
m sync.Mutex
done uint32
}
// Do simulates sync.Once.Do by executing the specified function
// only once, until Reset is called.
// See http://golang.org/pkg/sync/#Once
func (o *Once) Do(f func()) {
if atomic.LoadUint32(&o.done) == 1 {
return
}
// Slow-path.
o.m.Lock()
defer o.m.Unlock()
if o.done == 0 {
defer atomic.StoreUint32(&o.done, 1)
f()
}
}
// Reset indicates that the next call to Do should actually be called
// once again.
func (o *Once) Reset() {
o.m.Lock()
defer o.m.Unlock()
atomic.StoreUint32(&o.done, 0)
}

6
vendor/vendor.json vendored
View File

@ -332,12 +332,6 @@
"revision": "51463bfca2576e06c62a8504b5c0f06d61312647",
"revisionTime": "2017-03-21T09:30:39Z"
},
{
"checksumSHA1": "C4o27pZpCxioJpXbAL7NFYS9mrI=",
"path": "github.com/matryer/resync",
"revision": "d39c09a11215c84aab0b65e323fc47dd6e276af1",
"revisionTime": "2016-12-11T20:24:28Z"
},
{
"checksumSHA1": "V8CycX4FOqp+fAMzZeQY6TKv4AU=",
"path": "github.com/miekg/dns",