The reason it is hard to do is that Go correctly decided against this callback type code - it creates callback hell. Concurrency is cheap in Go, it is designed to use CSP or blocking procedural techniques - both far easier to maintain than callback focused systems.
> On Mar 8, 2019, at 7:19 AM, Haddock <ffm2...@web.de> wrote: > > I guess there is no way to get it accomplished. Non-local returns also don't > work on the JVM. What the Kotlin guys were doing to work around it was to use > inlining, see https://kotlinlang.org/docs/reference/inline-functions.html. In > Scala if the Scala compiler sees a non-lucal return, in the generated byte > code it wraps a try-catch block around it, assigns the return value to a > variable, throws an exception and in the catch block returns what was > previously stored in the variable. The approach in Kotlin is a little more > elegant (but not transparent for the developer as the approach in Scala). > > Now Go has no exceptions and no way to do inlining. So with the tricks that > come to my mind, I see no way to get it accomplished. > > Am Freitag, 8. März 2019 14:02:31 UTC+1 schrieb whiteh...@googlemail.com: >> >> I'm really liking in Go that I can easily pass bits of code around, >> 'closures'? Apologies if I have terminology wrong, since I'm new here. >> >> For a typical asynchronous bit of code I like to pass in a 'func' for what >> to do with the result, and also a 'func' to handle any errors. >> >> I'm struggling to find a clean way to achieve a 'non-local return' i.e. >> return from these closures and return the enclosing function too. >> >> https://play.golang.org/p/_ANPXKRzibq >> >> I had a look at the plan9 assembly stuff, and starting to suspect that it's >> probably not possible? >> >> So I'm wondering how readable my attempt is. In Objective-C I would use >> named parameters here of 'thenDo' and 'elseDo' to help the readability. And >> I'm reluctant to try and duplicate that approach using a struct in Go. But >> I suppose it's the dangling return that I least like... >> > > -- > 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. -- 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.