[Haskell-cafe] A Sliding TChan?

Eric O'Connor eric at oco.nnor.org
Thu Jan 28 21:57:23 UTC 2016


Perhaps a circular buffer interface to TArray would be nice:

data CircularTChan a = CircularTChan {
     tchanHead :: TVar Int
   , tchanLength :: TVar Int
   , tchanArray :: TArray Int (Maybe a)
   }

On 2016-01-28 13:30, Mark Fine wrote:
> We're currently using a TMChan to broadcast from a single producer
> thread to many consumer threads. This works well! However, we're
> seeing issues with a fast producer and/or a slow consumer, with the
> channel growing unbounded. Fortunately, our producer-consumer
> communication is time-sensitive and tolerant of loss: we're ok with
> the producer always writing at the expense of dropping communication
> to a slow consumer.
>
> A TMBChan provides a bounded channel (but no means to
> dupe/broadcast) where a writer will block once the channel fills up.
> In our use case, we'd like to continue writing to the channel but
> dropping off the end of the channel. Clojure's core-async module has
> some related concepts, in particular the notion of a sliding buffer
> <https://clojure.github.io/core.async/#clojure.core.async/sliding-buffer>
>
>
that drops the oldest elements once full. Has anyone encountered
> something similar in working with channels and/or have any
> solutions? Thanks!
>
> Mark
>
>
> _______________________________________________ Haskell-Cafe mailing
> list Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list