3 ms·
As far as I understand Go, passing back results via channels is the idiomatic approach for this. But the provided example is wrong - it is synchronous, as it a
by drdaeman 3y ago
As far as I understand Go, passing back results via channels is the idiomatic approach for this.
But the provided example is wrong - it is synchronous, as it awaits the computations to finish; and it is broken, because if either `refresh` call panics the caller will hang indefinitely. So it needs some extra defers and maybe a sync.WaitGroup
Also, example 5 is also somewhat not good, because it uses `if err == context.DeadlineExceeded` where it should've said `errors.Is(err, context.DeadlineExceeded)` as it's a good practice to always assume that exceptions may get wrapped (#4 just mentioned that).
- dvt 3y ago> As far as I understand Go, passing back results via channels is the idiomatic approach for this. It's definitely the canonical way, but communicating errors via channels feels very.. weird, for the lack of a better word (hence why I don't find it idiomatic).