fix concurrency issues in Compiler.Compile and Value.Source
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
cd0f21dbd2
commit
86aa031f92
@ -48,6 +48,9 @@ func (cc *Compiler) EmptyStruct() (*Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cc *Compiler) Compile(name string, src interface{}) (*Value, error) {
|
func (cc *Compiler) Compile(name string, src interface{}) (*Value, error) {
|
||||||
|
cc.Lock()
|
||||||
|
defer cc.Unlock()
|
||||||
|
|
||||||
inst, err := cc.Cue().Compile(name, src)
|
inst, err := cc.Cue().Compile(name, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// FIXME: cleaner way to unwrap cue error details?
|
// FIXME: cleaner way to unwrap cue error details?
|
||||||
|
@ -255,6 +255,9 @@ func (v *Value) Validate(defs ...string) error {
|
|||||||
|
|
||||||
// Return cue source for this value
|
// Return cue source for this value
|
||||||
func (v *Value) Source() ([]byte, error) {
|
func (v *Value) Source() ([]byte, error) {
|
||||||
|
v.cc.RLock()
|
||||||
|
defer v.cc.RUnlock()
|
||||||
|
|
||||||
return cueformat.Node(v.val.Eval().Syntax())
|
return cueformat.Node(v.val.Eval().Syntax())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user