Joey Adams | 31 Jul 20:09 2012

ANN: stm-sbchan-0.1 - STM channel with maximum total size of items

This package provides a bounded channel type for STM.  TBChan (in
stm-chans) and TBQueue (introduced in stm 2.4) are bounded channels
that limit the number of items in the channel.  SBChan, on the other
hand, limits the total size of items in the channel, where "size" is
defined by providing an instance of the ItemSize class:

    data Entry = Entry Int64 ByteString Time

    -- | Estimated amount of memory an 'Entry' requires,
    -- including channel overhead
    instance ItemSize Entry where
        itemSize (Entry _ s _) = B.length s + 200

Then, "SBChan Entry" is a channel that limits (approximately) the
amount of memory the entries take up.

SBChan can also be used as a regular count-bounded channel by using
the SBCItem newtype wrapper, where itemSize is always 1.


--- Implementation details ---

itemSize returns an Int.  I originally considered using an associated
type, so users could pick their own number type to use.  However, this
would have made the implementation harder to reason about, if we had
to worry about the user picking an ill-behaved number type like Float.
(Continue reading)