There may be a solution to the problem you have, but let me recommend you take a different approach and pre-compute RPC calls before calling the template. It will make your code easier to test and debug. Personally, the functions my templates call tend to be self-contained or zero dependencies: formatting a string, selecting items in a list, etc. It works better for me... YMMV.
Changing your code this way may require duplicating a loop outside the template and inside the template. For example, if the RPC call is made in a template loop, you'll then need a related loop to precompute the answers prior to the template. A change to the template will require a change to the code that precomputes values. That's a maintenance burden. However there may be situations where you can move the RPC-calling functions to a subtemplate <https://stackoverflow.com/questions/11467731/is-it-possible-to-have-nested-templates-in-go-using-the-standard-library-googl> and isolate the precompute code to be near there, to make maintenance easier. Best, Tom On Wed, May 31, 2017 at 1:28 AM, Michael Brown <michael.e.br...@gmail.com> wrote: > I am designing a system that will heavily use text/template processing and > I've run into one issue that is going to be a show stopper for me if I > can't figure out a way around it. > > Execute() on a template will run all of the functions in the template > serially. > > For example, when you run the code below, you can see it output "slept" > once every second until it completes after 3 seconds. In this example, the > sleep is simulating an RPC call to another process that may take some > considerable time (few tenths of a second), but there will be a large > number of these calls that could all theoretically run in parallel (ie. > there are no data dependencies between them). I'd really like to know a way > that I could have the templating engine run all of the functions at once > and collect the output, ie. in the example below, the entire program should > run in 1 second. > > package main > > > import ( > > "text/template" > > "os" > > "time" > > ) > > > var funcMap = template.FuncMap { > > "sleep": func() string { time.Sleep(1 * time.Second); return "slept" }, > > } > > > func main() { > > tmpl, _ := template.New("test").Funcs(funcMap).Parse("{{sleep}} > {{sleep}} {{sleep}}") > > tmpl.Execute(os.Stdout, nil) > > } > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Email: t...@whatexit.org Work: tlimonce...@stackoverflow.com Blog: http://EverythingSysadmin.com -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.