Closed lehins closed 5 years ago
It sounds like you're looking for better documentation, is that right? Were you expecting getChanContents
to return as many elements as it can from the queue (i.e. return a batch in a finite list)?
@jberryman, yes, precisely as you said, I was in need of a function that would give me full contents of the channel without blocking, i.e. would return an empty list if channel is empty, similar to flushTBQueue
. And I learned that it's definitely not what getChanContents
does :)
An improved documentation would certainly be a plus. At least something telling a user that he'll get an infinite list of values and warning of potential problems that can happen when using that function. But in general I would always advise people to avoid using lazy IO
. With getChanContents
you can do blocking inside of the pure code, which can be a potential source of problems, eg. receiving a BlockedIndefinitelyOnMVar
exception inside of pure code, which you would normally expect only be thrown inside of IO
. It might be a bad example, since that exception indicates an issue that you normally don't recover from, nevertheless it does explain the problem I am talking about.
I doubt that it's a feature, but getting contents of a channel (both bounded and unbounded) will exhaust computer resources quickly if the lazy list that gets produced gets reversed:
Conceptually it kind of make sense, but in practice it's terrible.