Lazy streams and unsafeInterleaveIO
William Lee Irwin III
Tue, 24 Dec 2002 10:47:32 -0800
On Mon, Dec 23, 2002 at 09:05:00AM +0000, Glynn Clements wrote:
> The main problems with lazy I/O are the lack of control over ordering
> (e.g. you can't delete the file until a stream has been closed, but
> you may not be able to control how long the stream remains open), and
> the inability to handle exceptions (the actual exception won't occur
> until after e.g. getContents has returned).
For my purposes it suffices to have a notion of when I'm done
generating output from the input stream and I close the handle then.
I basically just pass around the input file handles in perpetuity
and either don't close them until the last minute, as it's important to
clean up so I can reuse the action later, or until I'm done generating
output from a complete scan of the thing. This forces the evaluation of
the data structures created from the input, which may linger around
longer than the input stream itself.
Basically, I don't have these issues.
Actually, you -should- be able to delete the file before the stream has
been closed; this is a common idiom for dealing with temporary files.