3 ms·
What I mean is, to do the equivalent of async/await in Golang, you need to use channels. As I understand it, you can wait on a goroutine to finish by waiting on
by hot_gril 3y ago
What I mean is, to do the equivalent of async/await in Golang, you need to use channels. As I understand it, you can wait on a goroutine to finish by waiting on its channel to return something. Async/await would simply be syntactical sugar on top of that, it's already close.
One implication of async/await is that you need some kind of greenthreading or thread pool because you really don't want to spawn OS threads for it. In JS it's an event loop, Python and (I think) Rust have that too now as a lib, and Golang already has its own greenthreads.
And btw, the reason JS doesn't have threading is because for those applications, you don't need fast communication between parallel tasks like the things Golang is made for. NodeJS supports subprocessing, and the tasks will probably not talk to each other at all, though there's IPC if you really want it.
- lenkite 2y agoYou don't need to always use channels in Go. You can use the facilities of the sync package (https://pkg.go.dev/sync https://pkg.go.dev/sync) to communicate across go-routines.