3 ms·
Async/await allows you to be much more explicit about dependencies. I don’t care what thread executes something, but I do care that e.g. these three network req
by hinoki 4y ago
Async/await allows you to be much more explicit about dependencies. I don’t care what thread executes something, but I do care that e.g. these three network requests happen in parallel. With async/await I can explicitly use an ‘await Promise.all(a, b, c)’ where Go would need a new channel and goroutines, etc. all being implicit, so it’s hard for the reader to know what the intent is, and it’s error prone, who knows if you properly clean everything up.
- morelisp 4y agoThis is a weird example as Promise.all and Promise.race are what are pretty easy to write in Go: Promise.all is trivial: return <-a, <-b, <-c Promise.race is a little longer: select { case x := <-a: return x case x := <-b: return x case x := <-c: return x } What Go doesn't do very well compared to promises is composing; composing channels, especially with error returns, is usually tricky. But async/await are also bad at this. Passing around the actual promise/futures objects is the best way, which is for some reason discouraged today in favor of await/async noise in most cases.