Many "scripting" languages, Rebol included, have or had somewhat problematic handling of concurrency. One of the reasons I started writing Rye in Go was my naive reasoning, that because Go has very solid concurrency support Rye will be able to have it also. Rye is meant to be good at backend tasks and here concurrency is not unimportant. My naive assumption so far seems to be true.
Yesterday I re-implemented
web-sockets in gobwas and they work now. But to work with them in any meaningful
way I need some additiona concurrent mechanisms. And in Go-land they all start
with goroutines and channels. Goroutines are like green threads or coroutines and channels are used for communication between them. Unlike some green thread implementations that still run on one core, goroutines enable you to utilize multiple CPU cores.
First example uses gorotine and a channel, second creates a parallel http downloader with goroutines. Function go-with runs a function (with one argument) as a goroutine.
Note: pipe is just a function with one anonymous argument
This is all "alpha" level and can change. Next I need to add support for different number of arguments. I also need to implement some other mechanisms like WaitGroups, think about different kinds of channels, etc ...
I also need to get to know Go channels and goroutines better in the first place. So there is a lot of interesting "work" ahead.
Komentarji
Objavite komentar