Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Provides Write once read many (WORM) primitives
- package worm
- import (
- "sync"
- )
- // Object could be used to store interface{}
- // Object is safe for concurrent usage
- type Object struct {
- sync.RWMutex
- sealed bool
- v interface{}
- }
- func NewWithValue(v interface{}) Object {
- return Object{
- sealed: true,
- v: v,
- }
- }
- func (o Object) Set(v interface{}) {
- o.Lock()
- defer o.Unlock()
- if o.sealed {
- return
- }
- o.v = v
- o.sealed = true
- }
- func (o Object) Value() interface{} {
- o.RLock()
- v := o.v
- o.RUnlock()
- return v
- }
Add Comment
Please, Sign In to add comment