[Haskell-beginners] Re: how to read file with locking
Ertugrul Soeylemez
es at ertes.de
Mon Oct 11 01:39:01 EDT 2010
Joey Hess <joey at kitenet.net> wrote:
> Ertugrul Soeylemez wrote:
> > readFileLocked :: FilePath -> IO B.ByteString
> > readFileLocked fn =
> > withFile fn ReadMode $ \h -> do
> > lockFile h -- for a suitable function lockFile
> > B.hGetContents h
> >
> > It is, BTW, always preferable to use withFile over openFile, if you
> > can. This makes your code cleaner and also exception-safe.
>
> Unless there is a better locking primative than waitToSetLock
> available, I don't know how to build your lockFile function. It seems
> that it would have a side effect of closing the handle. It could
> return a new handle like this, but then withFile's automatic close of
> the file would be defeated.
I wasn't addressing the locking issue, but rather the laziness issue.
The lockFile function was just a placeholder.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Beginners
mailing list