git.iko.soy/distributed-process
on master help sign in
Additional raw message handling primitives
1dcdfa5Tim Watson
src/Control/Distributed/Process.hs+4
@@ -59,6 +59,8 @@ module Control.Distributed.Process
59 , unwrapMessage
59 , unwrapMessage
60 , handleMessage
60 , handleMessage
61 , handleMessageIf
61 , handleMessageIf
62+ , handleMessage_
63+ , handleMessageIf_
62 , forward
64 , forward
63 , delegate
65 , delegate
64 , relay
66 , relay
@@ -215,6 +217,8 @@ import Control.Distributed.Process.Internal.Primitives
215 , unwrapMessage
217 , unwrapMessage
216 , handleMessage
218 , handleMessage
217 , handleMessageIf
219 , handleMessageIf
220+ , handleMessage_
221+ , handleMessageIf_
218 , forward
222 , forward
219 , delegate
223 , delegate
220 , relay
224 , relay
src/Control/Distributed/Process/Internal/Primitives.hs+23
@@ -36,6 +36,8 @@ module Control.Distributed.Process.Internal.Primitives
36 , unwrapMessage
36 , unwrapMessage
37 , handleMessage
37 , handleMessage
38 , handleMessageIf
38 , handleMessageIf
39+ , handleMessage_
40+ , handleMessageIf_
39 , forward
41 , forward
40 , delegate
42 , delegate
41 , relay
43 , relay
@@ -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
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+--
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)
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-- | 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'.