git.iko.soy/distributed-process
on master help sign in
Expose NodeId’s constructor and introduce matchSTM
484b2cdTim Watson
src/Control/Distributed/Process.hs+3−1
@@ -16,7 +16,7 @@ please see the distributed-process wiki page on github:
16module Control.Distributed.Process
16module Control.Distributed.Process
17 ( -- * Basic types
17 ( -- * Basic types
18 ProcessId
18 ProcessId
19− , NodeId
19+ , NodeId(..)
20 , Process
20 , Process
21 , SendPortId
21 , SendPortId
22 , processNodeId
22 , processNodeId
@@ -51,6 +51,7 @@ module Control.Distributed.Process
51 , matchAny
51 , matchAny
52 , matchAnyIf
52 , matchAnyIf
53 , matchChan
53 , matchChan
54+ , matchSTM
54 , Message
55 , Message
55 , matchMessage
56 , matchMessage
56 , matchMessageIf
57 , matchMessageIf
@@ -209,6 +210,7 @@ import Control.Distributed.Process.Internal.Primitives
209 , matchAny
210 , matchAny
210 , matchAnyIf
211 , matchAnyIf
211 , matchChan
212 , matchChan
213+ , matchSTM
212 , matchMessage
214 , matchMessage
213 , matchMessageIf
215 , matchMessageIf
214 , isEncoded
216 , isEncoded
src/Control/Distributed/Process/Internal/Primitives.hs+18
@@ -28,6 +28,7 @@ module Control.Distributed.Process.Internal.Primitives
28 , matchAny
28 , matchAny
29 , matchAnyIf
29 , matchAnyIf
30 , matchChan
30 , matchChan
31+ , matchSTM
31 , matchMessage
32 , matchMessage
32 , matchMessageIf
33 , matchMessageIf
33 , isEncoded
34 , isEncoded
@@ -360,9 +361,26 @@ receiveTimeout t ms = do
360 Nothing -> return Nothing
361 Nothing -> return Nothing
361 Just proc -> Just <$> proc
362 Just proc -> Just <$> proc
362
363
364+-- | Match on a typed channel
363matchChan :: ReceivePort a -> (a -> Process b) -> Match b
365matchChan :: ReceivePort a -> (a -> Process b) -> Match b
364matchChan p fn = Match $ MatchChan (fmap fn (receiveSTM p))
366matchChan p fn = Match $ MatchChan (fmap fn (receiveSTM p))
365
367
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+
366-- | Match against any message of the right type
384-- | Match against any message of the right type
367match :: forall a b. Serializable a => (a -> Process b) -> Match b
385match :: forall a b. Serializable a => (a -> Process b) -> Match b
368match = matchIf (const True)
386match = matchIf (const True)