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

Miso.Concurrent

Description

Overview

Miso.Concurrent provides Waiter, a lightweight synchronization primitive built on MVar that the miso runtime uses to coordinate its event loop with subscription threads.

Two constructors are available with different wakeup semantics:

  • waitermany-to-one. Multiple threads may call notify concurrently; only one pending notification is retained at a time (tryPutMVar is used, so rapid notifications coalesce). The single consumer calls wait to block until at least one notification arrives.
  • oneshotone-to-many. One thread calls notify to permanently unblock all threads currently (or subsequently) calling wait. Implemented with readMVar, so the stored value is never consumed.

See also

Synopsis

Synchronization primitives

data Waiter Source #

Synchronization primitive for event loop

Constructors

Waiter 

Fields

  • wait :: IO ()

    Blocks on MVar

  • notify :: IO ()

    Unblocks threads waiting on MVar

waiter :: IO Waiter Source #

Creates a new Waiter

Useful for multiple threads to wake-up / notify a single thread running in an infinite loop, waiting for work (e.g. to process an event queue).

oneshot :: IO Waiter Source #

Creates a new Waiter

Useful for a single thread to wake-up multiple threads that are waiting to run a oneshot task (e.g. like forking a thread).