@@ -28,6 +28,7 @@ module Control.Distributed.Process.Internal.Primitives
28 , matchAny
28 , matchAny
29 , matchAnyIf
29 , matchAnyIf
30 , matchChan
30 , matchChan
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
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))
368+-- | Match on an arbitrary STM action.
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.
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.
378+-- Note there are no ordering guarnatees with respect to these disparate input
381+matchSTM :: STM a -> (a -> Process b) -> Match b
382+matchSTM stm fn = Match $ MatchChan (fmap fn stm)
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)