fix: avoid data racing.

This commit is contained in:
徐聪
2022-01-04 15:43:58 +08:00
parent 5d82873e1d
commit a60a6f6aef

View File

@@ -2,6 +2,7 @@ package hrp
import (
"math/rand"
"sync"
"time"
)
@@ -42,6 +43,7 @@ const (
type paramsType []map[string]interface{}
type Iterator struct {
sync.Mutex
data paramsType
strategy string // random, sequential
iteration int
@@ -64,6 +66,8 @@ func (iter *Iterator) HasNext() bool {
}
func (iter *Iterator) Next() (value map[string]interface{}) {
iter.Lock()
defer iter.Unlock()
iter.index++
if len(iter.data) == 0 {
return map[string]interface{}{}