polysemy-conc-0.14.1.1: Polysemy effects for concurrency
Safe HaskellNone
LanguageGHC2021

Polysemy.Conc.Interpreter.Events

Description

 
Synopsis

Documentation

type EventConsumer e = Scoped_ (Consume e) Source #

Convenience alias for the consumer effect.

interpretConsumeChan :: forall e (r :: EffectRow). Member (Embed IO) r => OutChan e -> InterpreterFor (Consume e) r Source #

Interpret Consume by reading from an OutChan. Used internally by interpretEventsChan, not safe to use directly.

interpretEventsInChan :: forall e (r :: EffectRow). Member (Embed IO) r => InChan e -> InterpreterFor (Events e) r Source #

Interpret Events by writing to an InChan. Used internally by interpretEventsChan, not safe to use directly. When the channel queue is full, this silently discards events.

interpretEventsChan :: forall e (r :: EffectRow). Members '[Resource, Race, Async, Embed IO] r => InterpretersFor '[Events e, EventConsumer e] r Source #

Interpret Events and Consume together by connecting them to the two ends of an unagi channel. Consume is only interpreted in a Scoped manner, ensuring that a new duplicate of the channel is created so that all consumers see all events (from the moment they are connected).

This should be used in conjunction with subscribe:

interpretEventsChan do
  async $ subscribe do
    putStrLn =<< consume
  publish "hello"

Whenever subscribe creates a new scope, this interpreter calls dupChan and passes the duplicate to interpretConsumeChan.