Hi,
Two questions about channels. I believe that we should do first (or something similar). The second question is whether we want to have something like in Go. There are plenty of examples and patterns about these, if you need motivation, then I'll write here some.
Q1. Currently if we close() a channel and there are still unread messages, then we can't read them. I think that this should be changed, because we could close() a channel to indicate that there won't be any more messages. Let's have three states:
Then we could have functions for test these (isAlive(), isDead(), isClosed(), isOpen). What do you think? If you like this, then I'll implement and send PR.
Q2. When we open() a channel then we could have an extra parameter for how many messages can be stored. Namely, if we open it with chan.open(3), and we try to send a message for the fourth time without reading so far, then it would block the fourth send(...) command until somebody reads from the channel. This should be optional, the default behavior would be no limit.
var T msg
while c.recv(msg):
print "received: ", msg
Regarding to Q2, I used and liked a pattern in Go, where a limit on the channel was useful. I started threads and each thread sent one message to the same channel, did some heavy work, then read one message just before exiting. The length of the buffer was set to the number of processors. I'll put it into a separate PR, so we can discuss separately.
I started threads and each thread sent one message to the same channel, did some heavy work, then read one message just before exiting. The length of the buffer was set to the number of processors.
That reads like a hacky way to do a barrier.