3 ms·
Maybe it is just me, but I prefer logically to think of actors (or processes) as concurrency primitives not channels, kind of like what Erlang has. For example
by rdtsc 13y ago
Maybe it is just me, but I prefer logically to think of actors (or processes) as concurrency primitives not channels, kind of like what Erlang has. For example in go the primary question is "what channel to I write or read from?", in Erlang it is "what is the pid of the process, so I can send it a message?".
- aufreak3 13y agoChannels are a neat generalization of what Erlang has. Btw the first example used in the post isn't all that "fall out of your chair". Here is the same implemented in pure JS using my toy IO.js library - https://gist.github.com/srikumarks/5992336 https://gist.github.com/srikumarks/5992336
- swannodette 13y agoPeople keep focusing on the first example. If you're going to compare, I think it's much more illuminating to see versions of the final example.
- aufreak3 13y agoChallenge accepted. https://gist.github.com/srikumarks/5992608 https://gist.github.com/srikumarks/5992608
- swannodette 13y agoThanks!
- deleted 13y ago[deleted]
- arnarbi 13y agoI like to view pids as a special case of a channel. A pid is just the one-and-only channel of a process, and a process cannot create more. If I'm not mistaken, Erlang advocates creating processes for very specific tasks, so most of the time one channel is enough. But if you ever find yourself writing processes that check the "type" of an incoming message and dispatch that to different handlers, then consider if it could be easier if each message type came in on a different channel. The security implications of channels are neat too, you can treat them as capabilities to specific parts of a process' API.
- alco 13y agoChannels by themselves are not a concurrency primitive. If you try to write and read from a channel in the same context, you'll deadlock. Goroutines (or "go blocks") provide the concurrent semantics, channels are a means of communication. In Go you don't actually ask "what channel do I read from?". You are handed a channel (as a function argument or as a value from another channel) which you can then use to communicate. From the encapsulation point of view, pids and channels are very similar -- the code using the channel/pid doesn't have to know anything about the other end. But the semantics of channels and message passing are very different: always synchronous vs asynchronous by default.