[racket] turning input-port into file-stream port

From: David T. Pierson (dtp at mindstory.com)
Date: Tue Nov 12 23:55:22 EST 2013

On Nov 12, 2013, at 4:04 PM, Vlad Kozin wrote:
> Can somebody pls have a look at this code. I can't figure out why it
> doesn't work. Input is certainly seen inside the background thread
> that I spawn to pump data from one port to another. But the main
> thread seems to receive an empty port.

Hi Vlad,

You have a synchronization problem.  The copy-port within foo starts
reading the input file stream and hits EOF before the copy-port within
the separate thread starts writing to the file.  Adding a sleep (hack
alert!) before returning from make-file-stream-input-port makes the
output appear:

http://pasterack.org/pastes/630

On Tue, Nov 12, 2013 at 04:07:09PM -0500, Vlad Kozin wrote:
> I should also mention that doing this by creating a temporary file
> feels incredibly hacky if only because it never gets deleted. If
> anyone can think of a better pattern pls share. 

I agree this feels hacky.  It isn't clear to me what you are trying to
accomplish.  Do you really need a file stream port and not just an input
port?  

David

Posted on the users mailing list.