@@ -36,6 +36,8 @@ module Control.Distributed.Process.Internal.Primitives
36
36
, unwrapMessage
37
37
, handleMessage
38
38
, handleMessageIf
39
+ , handleMessage_
40
+ , handleMessageIf_
39
41
, forward
40
42
, delegate
41
43
, relay
@@ -482,6 +484,11 @@ handleMessage :: forall m a b. (Monad m, Serializable a)
482
484
=> Message -> (a -> m b ) -> m (Maybe b )
483
485
handleMessage msg proc = handleMessageIf msg (const True ) proc
484
486
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
+ --
485
492
handleMessageIf :: forall m a b . (Monad m , Serializable a )
486
493
=> Message
487
494
-> (a -> Bool )
@@ -504,6 +511,22 @@ handleMessageIf msg c proc = do
504
511
decoded :: a -- note [decoding]
505
512
! decoded = decode (messageEncoding msg)
506
513
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
+
507
530
-- | Match against an arbitrary message. 'matchAny' removes the first available
508
531
-- message from the process mailbox. To handle arbitrary /raw/ messages once
509
532
-- removed from the mailbox, see 'handleMessage' and 'unwrapMessage'.
0 commit comments