That won't work if you want to create the name dynamically. It's also not very useful if you're in a debugger and want to navigate to a different goroutine.
I'm actually thinking about writing an RFC for a SetGoroutineName function to allow to customize the name. It will be strictly accessible only through the debugger or through stack traces, there will NOT be a GetGoroutineName counterpart. On Thursday, November 22, 2018 at 9:30:58 PM UTC-8, Michael Jones wrote: > > It is possible and easy to create named functions and launch them. > > a := func(stuff){morestuff} > > go a(args) > > On Thu, Nov 22, 2018 at 7:38 PM Russtopia <rma...@gmail.com <javascript:>> > wrote: > >> Perhaps this is actually supported in Go v1 and I'm just missing >> something simple, but it appears one can do >> >> func A() { >> go func() { >> ... >> }() >> } >> >> but not >> >> func A() { >> go func B() { >> ... >> }() >> } >> >> or even >> >> func A() { >> func B() { >> .. >> } >> >> go B() >> } >> >> Does the syntax just not allow naming a goroutine, or nested funcs that >> are *not* goroutines, at all? >> >> I think this would be a nice feature for two reasons: >> >> 1. It is, of course, possible to just move the goroutine out into an >> outside, named function, but then one must manually identify, declare and >> pass all the parameters the goroutine might otherwise automatically capture >> from its parent scope(s) when refactoring it. One loses the nice >> closure-ish syntax of goroutines; >> >> 2. It would allow tools such as graphviz to more easily generate diagrams >> that can name goroutines something meaningful other than "func$1" for a >> goroutine launched within "func". >> >> -Russ >> >> -- >> 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...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- > > *Michael T. jonesmichae...@gmail.com <javascript:>* > -- 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.