Skip to content

Commit 1dcdfa5

Browse files
committed
Additional raw message handling primitives
1 parent fe0a762 commit 1dcdfa5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Control/Distributed/Process.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ module Control.Distributed.Process
5959
, unwrapMessage
6060
, handleMessage
6161
, handleMessageIf
62+
, handleMessage_
63+
, handleMessageIf_
6264
, forward
6365
, delegate
6466
, relay
@@ -215,6 +217,8 @@ import Control.Distributed.Process.Internal.Primitives
215217
, unwrapMessage
216218
, handleMessage
217219
, handleMessageIf
220+
, handleMessage_
221+
, handleMessageIf_
218222
, forward
219223
, delegate
220224
, relay

src/Control/Distributed/Process/Internal/Primitives.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module Control.Distributed.Process.Internal.Primitives
3636
, unwrapMessage
3737
, handleMessage
3838
, handleMessageIf
39+
, handleMessage_
40+
, handleMessageIf_
3941
, forward
4042
, delegate
4143
, relay
@@ -482,6 +484,11 @@ handleMessage :: forall m a b. (Monad m, Serializable a)
482484
=> Message -> (a -> m b) -> m (Maybe b)
483485
handleMessage msg proc = handleMessageIf msg (const True) proc
484486

487+
-- | Conditionally handle a raw 'Message'.
488+
-- If the predicate @(a -> Bool)@ evaluates to @True@, invokes the supplied
489+
-- handler, other returns @Nothing@ to indicate failure. See 'handleMessage'
490+
-- for further information about runtime type checking.
491+
--
485492
handleMessageIf :: forall m a b . (Monad m, Serializable a)
486493
=> Message
487494
-> (a -> Bool)
@@ -504,6 +511,22 @@ handleMessageIf msg c proc = do
504511
decoded :: a -- note [decoding]
505512
!decoded = decode (messageEncoding msg)
506513

514+
-- | As 'handleMessage' but ignores result, which is useful if you don't
515+
-- care whether or not the handler succeeded.
516+
--
517+
handleMessage_ :: forall m a . (Monad m, Serializable a)
518+
=> Message -> (a -> m ()) -> m ()
519+
handleMessage_ msg proc = handleMessageIf_ msg (const True) proc
520+
521+
-- | Conditional version of 'handleMessage_'.
522+
--
523+
handleMessageIf_ :: forall m a . (Monad m, Serializable a)
524+
=> Message
525+
-> (a -> Bool)
526+
-> (a -> m ())
527+
-> m ()
528+
handleMessageIf_ msg c proc = handleMessageIf msg c proc >> return ()
529+
507530
-- | Match against an arbitrary message. 'matchAny' removes the first available
508531
-- message from the process mailbox. To handle arbitrary /raw/ messages once
509532
-- removed from the mailbox, see 'handleMessage' and 'unwrapMessage'.

0 commit comments

Comments
 (0)