@@ -102,10 +102,20 @@ The ``channel`` class
102102.. method :: channel.send_sequence(seq)
103103
104104 Send a stream of values over the channel. Combined with a generator, this
105- is a very efficient way to build fast pipes.
105+ is a very efficient way to build fast pipes. This method returns the length
106+ of *seq *.
107+
108+ This method is equivalent to::
109+
110+ def send_sequence(channel, sequence):
111+ length = 0
112+ for item in sequence:
113+ channel.send(item)
114+ length += 1
115+ return length
106116
107117 Example - sending a sequence over a channel::
108-
118+
109119 >>> def sender(channel):
110120 ... channel.send_sequence(sequence)
111121 ...
@@ -135,11 +145,23 @@ The ``channel`` class
135145 Channels can work as an iterator. When they are used in this way, call
136146 overhead is removed on the receiving side, making it an efficient approach.
137147
148+ The receiver does not know, if the sender will send further objects
149+ or not. Therefore the sender must notify the receiver about the
150+ end-of-iteration condition. Currently this requires sending a
151+ :exc: `StopIteration ` over the channel (i.e. by
152+ calling ``channel.send_exception(StopIteration) ``).
153+
154+ .. note ::
155+
156+ A future version of Stackless may send a :exc: `StopIteration ` automatically,
157+ if you close the channel.
158+
138159 Example - iterating over a channel::
139160
140161 >>> def sender(channel):
141162 ... for value in sequence:
142163 ... channel.send(value)
164+ ... channel.send_exception(StopIteration)
143165 ...
144166 >>> def receiver(channel):
145167 ... for value in channel:
@@ -159,6 +181,27 @@ The ``channel`` class
159181 2
160182 3
161183
184+ Of course you can combine :meth: `send_sequence ` with iterating over a channel::
185+
186+ >>> def sender(channel, sequence):
187+ ... channel.send_sequence(sequence)
188+ ... channel.send_exception(StopIteration)
189+ ...
190+ >>> def receiver(channel):
191+ ... for value in channel:
192+ ... print value
193+ ...
194+ >>> c = stackless.channel()
195+ >>> stackless.tasklet(sender)(c, range(4))
196+ <_stackless.tasklet object at 0x0244E0E8>
197+ >>> stackless.tasklet(receiver)(c)
198+ <_stackless.tasklet object at 0x0244E140>
199+ >>> stackless.run()
200+ 0
201+ 1
202+ 2
203+ 3
204+
162205.. method :: channel.next()
163206
164207 Part of the :ref: `iteration protocol <typeiter >`. Either returns the next value, or raises
0 commit comments