BSD-3-Clause licensed by Athan Clark
Maintained by [email protected]
This version can be pinned in stack with:chan-0.0.3@sha256:ab6023b5f466b0e297ff1604ed527d7d74cd0027bfab64f06d362d96dc31338c,1474

Module documentation for 0.0.3

  • Control
    • Control.Concurrent
      • Control.Concurrent.Chan
        • Control.Concurrent.Chan.Extra
        • Control.Concurrent.Chan.Scope
        • Control.Concurrent.Chan.Typed
          • Control.Concurrent.Chan.Typed.Extra
      • Control.Concurrent.STM
        • Control.Concurrent.STM.TChan
          • Control.Concurrent.STM.TChan.Extra
          • Control.Concurrent.STM.TChan.Typed
            • Control.Concurrent.STM.TChan.Typed.Extra
Depends on 3 packages(full list with versions):

chan

This is just some extra Chan and TChan kit that might help the average user. It relies on spawning threads with async and either canceling (debouncing) or waiting (throttling) messages.

Unfortunately, the current design is untyped in the sense that the channel which you supply is the output channel, and the returned channel is the one you would write to. I’m not sure how this should be fixed.

An example might be the following:

import Control.Concurrent.Chan (readChan)
import Control.Concurrent.Chan.Extra (throttleStatic, intersperseStatic)



-- For example, some websockets:

data SomeMessage
  = Ping
  -- | ...

throttleLayer :: Chan SomeMessage -> IO (Chan SomeMessage)
throttleLayer output = do
  (x,_) <- throttleStatic output 1000000 -- nanoseconds, = 1 second
  pure x

pingLayer :: Chan SomeMessage -> IO (Chan SomeMessage)
pingLayer output = do
  (x,_,_) <- intersperseStatic output (pure Ping) 1000000
  pure x

performWebsocket :: Chan SomeMessage -> IO ()
performWebsocket output = do
  output' <- pingLayer =<< throttleLayer output
  _ <- async $ forever $ do
    msg <- readChan output'
    send msg -- something like that - it'll include Ping messages for us,
             -- and throttle the outgoing messages at the same time.