Allow library to be used in parallel
This PR allows concurrent calls to Parse. Further it makes the test be part of the same package. Fixes https://github.com/gorhill/cronexpr/issues/26
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -194,6 +195,7 @@ var (
|
||||
fieldFinder = regexp.MustCompile(`\S+`)
|
||||
entryFinder = regexp.MustCompile(`[^,]+`)
|
||||
layoutRegexp = make(map[string]*regexp.Regexp)
|
||||
layoutRegexpLock sync.Mutex
|
||||
)
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -488,6 +490,9 @@ func genericFieldParse(s string, desc fieldDescriptor) ([]*cronDirective, error)
|
||||
/******************************************************************************/
|
||||
|
||||
func makeLayoutRegexp(layout, value string) *regexp.Regexp {
|
||||
layoutRegexpLock.Lock()
|
||||
defer layoutRegexpLock.Unlock()
|
||||
|
||||
layout = strings.Replace(layout, `%value%`, value, -1)
|
||||
re := layoutRegexp[layout]
|
||||
if re == nil {
|
||||
|
||||
Reference in New Issue
Block a user