HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleunagi-chan-0.4.1.4Haskell2010

Control.Concurrent.Chan.Unagi.Unboxed

  • 3 types
  • 1 class
  • 8 values

Creating channels

4 declarations
newtypenewtype InChan a
#

The write end of a channel created with newChan.

Instances1Eq
  • Eq (InChan a)Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
newtypenewtype OutChan a
#

The read end of a channel created with newChan.

Instances1Eq
  • Eq (OutChan a)Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
classclass (Prim a, Eq a) => UnagiPrim a where
#

Our class of types supporting primitive array operations. Instance method definitions are architecture-dependent.

Methods

  • atomicUnicorn :: Maybe a

    When the read and write operations of the underlying Prim instances on aligned memory are atomic, this may be set to Just x where x is some rare (i.e. unlikely to occur frequently in your data) magic value; this might help speed up some UnagiPrim operations.

    Where those Prim instance operations are not atomic, this *must* be set to Nothing.

Instances14UnagiPrim, …
  • UnagiPrim Int16Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Int32Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Int64Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Int8Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Word16Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Word32Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Word64Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim Word8Defined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim CharDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim DoubleDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim FloatDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim IntDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim WordDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal
  • UnagiPrim AddrDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.Unboxed.Internal

Channel operations

0 declarations

Reading

valuereadChan :: UnagiPrim a => OutChan a -> IO a
#

Read an element from the chan, blocking if the chan is empty.

Note re. exceptions: When an async exception is raised during a readChan the message that the read would have returned is likely to be lost, even when the read is known to be blocked on an empty queue. If you need to handle this scenario, you can use readChanOnException.

valuereadChanOnException :: UnagiPrim a => OutChan a -> (IO a -> IO ()) -> IO a
#

Like readChan but allows recovery of the queue element which would have been read, in the case that an async exception is raised during the read. To be precise exceptions are raised, and the handler run, only when readChanOnException is blocking.

The second argument is a handler that takes a blocking IO action returning the element, and performs some recovery action. When the handler is called, the passed IO a is the only way to access the element.

valuetryReadChan :: UnagiPrim a => OutChan a -> IO (Element a, IO a)
#

Returns immediately with:

  • an Element a future, which returns one unique element when it becomes available via tryRead.

  • a blocking IO action that returns the element when it becomes available.

Note: This is a destructive operation. See Element for more details.

If you're using this function exclusively you might find the implementation in Control.Concurrent.Chan.Unagi.NoBlocking.Unboxed is faster.

Note re. exceptions: When an async exception is raised during a tryReadChan the message that the read would have returned is likely to be lost, just as it would be when raised directly after this function returns.

newtypenewtype Element a
#

An IO action that returns a particular enqueued element when and if it becomes available.

Each Element corresponds to a particular enqueued element, i.e. a returned Element always offers the only means to access one particular enqueued item. The value returned by tryRead moves monotonically from Nothing to Just a when and if an element becomes available, and is idempotent at that point.

So for instance:

   (in, out) <- newChan
   (el, _) <- tryReadChan out  -- READ FROM EMPTY CHAN
   writeChan in "msg1"
   writeChan in "msg2"
   readChan out        -- RETURNS "msg2"
   tryRead el          -- RETURNS "msg1" (which would otherwise be lost)

Constructors

Instances7Monad, Functor, MonadFix, MonadFail, Applicative, Alternative, …
  • Monad ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • Functor ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • MonadFix ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • MonadFail ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • Applicative ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • Alternative ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
  • MonadPlus ElementDefined in unagi-chan-0.4.1.4 · Control.Concurrent.Chan.Unagi.NoBlocking.Types
valuegetChanContents :: UnagiPrim a => OutChan a -> IO [a]
#

Return a lazy infinite list representing the contents of the supplied OutChan, much like System.IO.hGetContents.

Writing

valuewriteList2Chan :: UnagiPrim a => InChan a -> [a] -> IO ()
#

Write an entire list of items to a chan type. Writes here from multiple threads may be interleaved, and infinite lists are supported.

Broadcasting

valuedupChan :: InChan a -> IO (OutChan a)
#

Duplicate a chan: the returned OutChan begins empty, but data written to the argument InChan from then on will be available from both the original OutChan and the one returned here, creating a kind of broadcast channel.