mirror of
https://github.com/number571/go-peer.git
synced 2026-09-14 02:55:43 +05:00
35 lines
498 B
Go
35 lines
498 B
Go
package wrapper
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
_ IWrapper = &sWrapper{}
|
|
)
|
|
|
|
type sWrapper struct {
|
|
fMutex sync.Mutex
|
|
fValue *interface{}
|
|
}
|
|
|
|
// Used to set values at the time of execution.
|
|
func NewWrapper() IWrapper {
|
|
return &sWrapper{fValue: new(interface{})}
|
|
}
|
|
|
|
func (p *sWrapper) Get() interface{} {
|
|
p.fMutex.Lock()
|
|
defer p.fMutex.Unlock()
|
|
|
|
return (*p.fValue)
|
|
}
|
|
|
|
func (p *sWrapper) Set(pValue interface{}) IWrapper {
|
|
p.fMutex.Lock()
|
|
defer p.fMutex.Unlock()
|
|
|
|
(*p.fValue) = pValue
|
|
return p
|
|
}
|