[plt-scheme] Waiting for multiple events

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Wed Jul 30 01:24:20 EDT 2008

have a set of events I want to occur before my main thread proceeds,  
but I don't care about the order. (Actually, it doesn't matter that  
much if I wait for them in a given order, but in this case, I don't  
need that.)

The idea is that I use for/list to create a set of client threads in  
my test suite, like so

(let ([clients
            (for/list ((i (in-range 1 5)))
              (thread
               (lambda ()
                 (let-values ([(in out) (tcp-connect "localhost" port- 
no)])
...

The list clients contains the client threads I've just spawned. Now,  
what I do to wait for them seems a little crazy, but it seems to work


...
    (map sync clients))
     (printf "Stopping server\n")
       (stop)))

Mapping sync to a list of events seems strange, but it seems to work.  
Intuitively, I suspect that the compiler will carry out (sync  
thd-1 ..., (sync thd-2 ..., etc. in "parallel".

I thought about transforming this to (sync thd-1 (sync thd-2 ....))  
but that seemed unnecessary, and it does force the events to be ordered.

I see from the manual that I can use choice-evt to wait for any of  
several events, but there doesn't seem to a comparable every-event  
that would become ready once each of evt-1, evt-2, ..., evt-n is ready.

Am I missing something?




Metaphors be with you.

http://www.gwoodhouse.com
http://GregWoodhouse.ImageKind.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080729/7dec74d6/attachment.html>

Posted on the users mailing list.