File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ please see the distributed-process wiki page on github:
16
16
module Control.Distributed.Process
17
17
( -- * Basic types
18
18
ProcessId
19
- , NodeId
19
+ , NodeId ( .. )
20
20
, Process
21
21
, SendPortId
22
22
, processNodeId
@@ -51,6 +51,7 @@ module Control.Distributed.Process
51
51
, matchAny
52
52
, matchAnyIf
53
53
, matchChan
54
+ , matchSTM
54
55
, Message
55
56
, matchMessage
56
57
, matchMessageIf
@@ -209,6 +210,7 @@ import Control.Distributed.Process.Internal.Primitives
209
210
, matchAny
210
211
, matchAnyIf
211
212
, matchChan
213
+ , matchSTM
212
214
, matchMessage
213
215
, matchMessageIf
214
216
, isEncoded
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ module Control.Distributed.Process.Internal.Primitives
28
28
, matchAny
29
29
, matchAnyIf
30
30
, matchChan
31
+ , matchSTM
31
32
, matchMessage
32
33
, matchMessageIf
33
34
, isEncoded
@@ -360,9 +361,26 @@ receiveTimeout t ms = do
360
361
Nothing -> return Nothing
361
362
Just proc -> Just <$> proc
362
363
364
+ -- | Match on a typed channel
363
365
matchChan :: ReceivePort a -> (a -> Process b ) -> Match b
364
366
matchChan 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
384
-- | Match against any message of the right type
367
385
match :: forall a b . Serializable a => (a -> Process b ) -> Match b
368
386
match = matchIf (const True )
You can’t perform that action at this time.
0 commit comments