miso
Copyright(C) 2016-2025 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Concurrent

Description

 
Synopsis

Syncrhonization primitives

data Waiter Source #

Synchronization primitive for event loop

Constructors

Waiter 

Fields

  • wait :: IO ()

    Blocks on MVar

  • serve :: IO ()

    Unblocks threads waiting on MVar

waiter :: IO Waiter Source #

Creates a new Waiter

type Mailbox = TChan Mail Source #

Publish / Subscribe concurrency primitive

A Mailbox is a broadcast TChan that can express the following concurrency patterns

  • Broadcast (one-to-all, 1:n)
  • Multicast (one-to-many, 1:n)
  • Unicast (one-to-one, 1:1)

All the above are supported as well in a bidirectional setting.

  • Bidirectional (multicast broadcast unicast) (n:m)

Practically this pattern resembles cloud notifcation services like

  • Amazon SNS
  • Google Pub/Sub

See 'examplescomponentsMain.hs' for example usage.

type Mail = Value Source #

Type for expressing Mail (or message payloads) put into a Mailbox for delivery

newMailbox :: IO Mailbox Source #

Constructs a new Mailbox

copyMailbox :: Mailbox -> IO Mailbox Source #

Duplicates a Mailbox, all new Mail is sent to all duplicated Mailbox

sendMail :: Mailbox -> Mail -> IO () Source #

Sends mail to a mailbox, all duplicated Mailbox receive the same message.

readMail :: Mailbox -> IO Mail Source #

Reads mail from a Mailbox. This only works on a duplicated Mailbox. So call this function only on Mailbox that have been created from copyMailbox.