git.iko.soy/distributed-process
on master help sign in
Expose NodeId’s constructor and introduce matchSTM

Various clients need to construct NodeId’s, notably all the various CH backends, so it needs to be public. Also provide a match primitive that can be used to compose STM actions with the receive family of functions.

commit484b2cd8d22c12572424663ac20ce2c540177c08 authorTim Watson <watson.timothy@gmail.com> dateSat 18 Jan 2014, 22:20 (13 years ago) parent28ebac4
2 files changed+21−1
src/Control/Distributed/Process.hs+3−1 src/Control/Distributed/Process/Internal/Primitives.hs+18
src/Control/Distributed/Process.hs+3−1
@@ -16,7 +16,7 @@ please see the distributed-process wiki page on github:
1616module Control.Distributed.Process
1717 ( -- * Basic types
1818 ProcessId
19− , NodeId
19+ , NodeId(..)
2020 , Process
2121 , SendPortId
2222 , processNodeId
@@ -51,6 +51,7 @@ module Control.Distributed.Process
5151 , matchAny
5252 , matchAnyIf
5353 , matchChan
54+ , matchSTM
5455 , Message
5556 , matchMessage
5657 , matchMessageIf
@@ -209,6 +210,7 @@ import Control.Distributed.Process.Internal.Primitives
209210 , matchAny
210211 , matchAnyIf
211212 , matchChan
213+ , matchSTM
212214 , matchMessage
213215 , matchMessageIf
214216 , isEncoded
src/Control/Distributed/Process/Internal/Primitives.hs+18
@@ -28,6 +28,7 @@ module Control.Distributed.Process.Internal.Primitives
2828 , matchAny
2929 , matchAnyIf
3030 , matchChan
31+ , matchSTM
3132 , matchMessage
3233 , matchMessageIf
3334 , isEncoded
@@ -360,9 +361,26 @@ receiveTimeout t ms = do
360361 Nothing -> return Nothing
361362 Just proc -> Just <$> proc
362363
364+-- | Match on a typed channel
363365matchChan :: ReceivePort a -> (a -> Process b) -> Match b
364366matchChan p fn = Match $ MatchChan (fmap fn (receiveSTM p))
365367
368+-- | Match on an arbitrary STM action.
369+--
370+-- This rather unusaul /match primitive/ allows us to compose arbitrary STM
371+-- actions with checks against our process' mailbox and/or any typed channel
372+-- @ReceivePort@s we may hold.
373+--
374+-- This allows us to process multiple input streams /along with our mailbox/,
375+-- in just the same way that 'matchChan' supports checking both the mailbox
376+-- /and/ an arbitrary set of typed channels in one atomic transaction.
377+--
378+-- Note there are no ordering guarnatees with respect to these disparate input
379+-- sources.
380+--
381+matchSTM :: STM a -> (a -> Process b) -> Match b
382+matchSTM stm fn = Match $ MatchChan (fmap fn stm)
383+
366384-- | Match against any message of the right type
367385match :: forall a b. Serializable a => (a -> Process b) -> Match b
368386match = matchIf (const True)