Skip to content

Commit 484b2cd

Browse files
committed
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.
1 parent 28ebac4 commit 484b2cd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Control/Distributed/Process.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ please see the distributed-process wiki page on github:
1616
module 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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
363365
matchChan :: ReceivePort a -> (a -> Process b) -> Match b
364366
matchChan 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
367385
match :: forall a b. Serializable a => (a -> Process b) -> Match b
368386
match = matchIf (const True)

0 commit comments

Comments
 (0)