@@ -36,6 +36,8 @@ module Control.Distributed.Process.Internal.Primitives
36 , unwrapMessage
36 , unwrapMessage
37 , handleMessage
37 , handleMessage
38 , handleMessageIf
38 , handleMessageIf
40 , delegate
42 , delegate
@@ -482,6 +484,11 @@ handleMessage :: forall m a b. (Monad m, Serializable a)
482 => Message -> (a -> m b) -> m (Maybe b)
484 => Message -> (a -> m b) -> m (Maybe b)
483handleMessage msg proc = handleMessageIf msg (const True) proc
485handleMessage msg proc = handleMessageIf msg (const True) proc
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.
485handleMessageIf :: forall m a b . (Monad m, Serializable a)
492handleMessageIf :: forall m a b . (Monad m, Serializable a)
486 => Message
493 => Message
487 -> (a -> Bool)
494 -> (a -> Bool)
@@ -504,6 +511,22 @@ handleMessageIf msg c proc = do
504 decoded :: a -- note [decoding]
511 decoded :: a -- note [decoding]
505 !decoded = decode (messageEncoding msg)
512 !decoded = decode (messageEncoding msg)
514+-- | As 'handleMessage' but ignores result, which is useful if you don't
515+-- care whether or not the handler succeeded.
517+handleMessage_ :: forall m a . (Monad m, Serializable a)
518+ => Message -> (a -> m ()) -> m ()
519+handleMessage_ msg proc = handleMessageIf_ msg (const True) proc
521+-- | Conditional version of 'handleMessage_'.
523+handleMessageIf_ :: forall m a . (Monad m, Serializable a)
528+handleMessageIf_ msg c proc = handleMessageIf msg c proc >> return ()
507-- | Match against an arbitrary message. 'matchAny' removes the first available
530-- | Match against an arbitrary message. 'matchAny' removes the first available
508-- message from the process mailbox. To handle arbitrary /raw/ messages once
531-- message from the process mailbox. To handle arbitrary /raw/ messages once
509-- removed from the mailbox, see 'handleMessage' and 'unwrapMessage'.
532-- removed from the mailbox, see 'handleMessage' and 'unwrapMessage'.