[racket] custom port question

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Sep 6 20:07:20 EDT 2012

At Thu, 6 Sep 2012 16:43:09 -0700, Kartik Agaram wrote:
> I'm trying to build an output port that acts like 'tee', wrapping two
> (or more) output ports and duplicating writes to them. This requires
> make-output-port
> (http://docs.racket-lang.org/reference/customport.html#%28def._%28%28quote._~23
> ~25kernel%29._make-output-port%29%29),
> right? I'm trying to think about what the evt arg to make-output-port
> should be. It needs to be the AND of the sync-readiness of all the
> constituent ports, right? Is there a way to specify that? choice-evt
> (http://docs.racket-lang.org/reference/sync.html#%28def._%28%28quote._~23~25ker
> nel%29._choice-evt%29%29)
> is an OR, if I'm reading the docs right..

No, there's no way to "and" events. (Racket's scheduler provides 1-way
rendezvous, and it turns out that you can't get to N-way rendezvous
from 1-way rendezvous.)

The only way out is to always internally buffer at least one byte. From
the outside, the byte counts as committed to the port at the point that
it's internally buffered; don't accept more bytes until the buffer can
be cleared. Your output port will likely provide the guarantee that all
bytes are delivered to the destination ports only when it is finally
closed.


Posted on the users mailing list.