Commit aeb37527 authored by Rob Pike's avatar Rob Pike

text/template: say more often that templates are safe for parallel execution

It was said already but apparently not enough times.

Fixes #6985.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/86300043
parent 55e0f36f
......@@ -62,6 +62,7 @@ func (t *Template) escape() error {
// Execute applies a parsed template to the specified data object,
// writing the output to wr.
// A template may be executed safely in parallel.
func (t *Template) Execute(wr io.Writer, data interface{}) error {
if err := t.escape(); err != nil {
return err
......@@ -71,6 +72,7 @@ func (t *Template) Execute(wr io.Writer, data interface{}) error {
// ExecuteTemplate applies the template associated with t that has the given
// name to the specified data object and writes the output to wr.
// A template may be executed safely in parallel.
func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
tmpl, err := t.lookupAndEscapeTemplate(name)
if err != nil {
......
......@@ -20,7 +20,7 @@ The input text for a template is UTF-8-encoded text in any format.
"{{" and "}}"; all text outside actions is copied to the output unchanged.
Actions may not span newlines, although comments can.
Once constructed, a template may be executed safely in parallel.
Once parsed, a template may be executed safely in parallel.
Here is a trivial example that prints "17 items are made of wool".
......
......@@ -108,6 +108,7 @@ func errRecover(errp *error) {
// ExecuteTemplate applies the template associated with t that has the given name
// to the specified data object and writes the output to wr.
// A template may be executed safely in parallel.
func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
tmpl := t.tmpl[name]
if tmpl == nil {
......@@ -118,6 +119,7 @@ func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{})
// Execute applies a parsed template to the specified data object,
// and writes the output to wr.
// A template may be executed safely in parallel.
func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
defer errRecover(&err)
value := reflect.ValueOf(data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment