Skip to content

Commit

Permalink
take a lock on the whole function to simplify mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
adnaan committed Feb 15, 2024
1 parent 9bee96e commit 62d6207
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,44 +266,32 @@ func (rt *route) getChannel() string {

// set route template concurrency safe
func (rt *route) setTemplate(t *template.Template) {
rt.Lock()
defer rt.Unlock()
rt.template = t
}

// get route template concurrency safe

func (rt *route) getTemplate() *template.Template {
rt.RLock()
defer rt.RUnlock()
return rt.template
}

// set route error template concurrency safe
func (rt *route) setErrorTemplate(t *template.Template) {
rt.Lock()
defer rt.Unlock()
rt.errorTemplate = t
}

// get route error template concurrency safe
func (rt *route) getErrorTemplate() *template.Template {
rt.RLock()
defer rt.RUnlock()
return rt.errorTemplate
}

// set event templates concurrency safe
func (rt *route) setEventTemplates(templates eventTemplates) {
rt.Lock()
defer rt.Unlock()
rt.eventTemplates = templates
}

// get event templates concurrency safe
func (rt *route) getEventTemplates() eventTemplates {
rt.RLock()
defer rt.RUnlock()
return rt.eventTemplates
}

Expand Down Expand Up @@ -667,6 +655,8 @@ func handleOnLoadResult(err, onFormErr error, ctx RouteContext) {
}

func (rt *route) parseTemplates() {
rt.Lock()
defer rt.Unlock()
var err error
if rt.getTemplate() == nil || (rt.getTemplate() != nil && rt.disableTemplateCache) {
var successEventTemplates eventTemplates
Expand Down

0 comments on commit 62d6207

Please sign in to comment.