On Nov 12, 2009, at 9:40 PM, Andrew Francis wrote:
That said, one feature that would be nice to have in Stackless as a
language feature would be select, where one is waiting on multiple
channels. Yes this could be built as library but it is not as nice.
One of the Go demos is
func server(op binOp, service chan *request, quit chan bool) {
for {
select {
case req := <-service:
go run(op, req); // don't wait for it
case <-quit:
return;
}
}
}
Doing this in stackless seems complicated. The solution I see would be
def forward_requests(name, from_ch, to_ch):
for item in from_ch:
to_ch.send( (name, item) )
common_channel = channel()
tasklet(forward_requests)("req", request, common_channel)
tasklet(forward_requsts)("quit", quit, common_channel)
for tag, item in common_channel():
if tag == "quit":
return
elif tag == "req":
tasklet(run)(op, req)
This could be wrapped up in a function like, perhaps,
def select(**kwargs):
common_channel = channel()
for name, from_ch in kwargs.items():
forward_requests(name, from_ch, common_channel)
return common_channel
making the entire process
for (name, event) in select(quit=quit, req=request)
if name == "quit":
return
elif tag == "req":
tasklet(run)(op, req)
Is this clean? Elegant? A hack? I don't recall people bringing up the
need for something like it before.
Andrew
[email protected]
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless