aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/list.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/ethutil/list.go b/ethutil/list.go
index 4fb36224f..6919a02f5 100644
--- a/ethutil/list.go
+++ b/ethutil/list.go
@@ -3,12 +3,14 @@ package ethutil
import (
"encoding/json"
"reflect"
+ "sync"
)
// The list type is an anonymous slice handler which can be used
// for containing any slice type to use in an environment which
// does not support slice types (e.g., JavaScript, QML)
type List struct {
+ mut sync.Mutex
val interface{}
list reflect.Value
Length int
@@ -21,7 +23,7 @@ func NewList(t interface{}) *List {
panic("list container initialized with a non-slice type")
}
- return &List{t, list, list.Len()}
+ return &List{sync.Mutex{}, t, list, list.Len()}
}
func EmptyList() *List {
@@ -30,8 +32,10 @@ func EmptyList() *List {
// Get N element from the embedded slice. Returns nil if OOB.
func (self *List) Get(i int) interface{} {
-
if self.list.Len() > i {
+ self.mut.Lock()
+ defer self.mut.Unlock()
+
i := self.list.Index(i).Interface()
return i
@@ -51,6 +55,9 @@ func (self *List) GetAsJson(i int) interface{} {
// Appends value at the end of the slice. Panics when incompatible value
// is given.
func (self *List) Append(v interface{}) {
+ self.mut.Lock()
+ defer self.mut.Unlock()
+
self.list = reflect.Append(self.list, reflect.ValueOf(v))
self.Length = self.list.Len()
}