git.iko.soy/distributed-process
on master help sign in
Additional raw message handling primitives
commit1dcdfa5c3481b6b9f1abf1ec173f44fb30855703 authorTim Watson <watson.timothy@gmail.com> dateMon 13 Jan 2014, 17:16 (13 years ago) parentfe0a762
2 files changed+27
src/Control/Distributed/Process.hs+4 src/Control/Distributed/Process/Internal/Primitives.hs+23
src/Control/Distributed/Process.hs+4
@@ -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+23
@@ -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)
483485handleMessage 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+--
485492handleMessageIf :: 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'.