git.iko.soy/distributed-process
on master help sign in
Improve docs
a519bcfEdsko de Vries
distributed-process/src/Control/Distributed/Process.hs+9
@@ -222,9 +222,11 @@ newChan = do
222 , (sport, rport)
222 , (sport, rport)
223 )
223 )
224
224
225+-- | Send a message on a typed channel
225sendChan :: Serializable a => SendPort a -> a -> Process ()
226sendChan :: Serializable a => SendPort a -> a -> Process ()
226sendChan (SendPort them) msg = lift $ sendBinary (ChannelIdentifier them) msg
227sendChan (SendPort them) msg = lift $ sendBinary (ChannelIdentifier them) msg
227
228
229+-- | Wait for a message on a typed channel
228receiveChan :: Serializable a => ReceivePort a -> Process a
230receiveChan :: Serializable a => ReceivePort a -> Process a
229receiveChan = liftIO . atomically . receiveSTM
231receiveChan = liftIO . atomically . receiveSTM
230 where
232 where
@@ -243,9 +245,15 @@ receiveChan = liftIO . atomically . receiveSTM
243 rotate [] = []
245 rotate [] = []
244 rotate (x:xs) = xs ++ [x]
246 rotate (x:xs) = xs ++ [x]
245
247
248+-- | Merge a list of typed channels.
249+--
250+-- The result port is left-biased: if there are messages available on more
251+-- than one port, the first available message is returned.
246mergePortsBiased :: Serializable a => [ReceivePort a] -> Process (ReceivePort a)
252mergePortsBiased :: Serializable a => [ReceivePort a] -> Process (ReceivePort a)
247mergePortsBiased = return . ReceivePortBiased
253mergePortsBiased = return . ReceivePortBiased
248
254
255+-- | Like 'mergePortsBiased', but with a round-robin scheduler (rather than
256+-- left-biased)
249mergePortsRR :: Serializable a => [ReceivePort a] -> Process (ReceivePort a)
257mergePortsRR :: Serializable a => [ReceivePort a] -> Process (ReceivePort a)
250mergePortsRR ps = liftIO . atomically $ ReceivePortRR <$> newTVar ps
258mergePortsRR ps = liftIO . atomically $ ReceivePortRR <$> newTVar ps
251
259
@@ -312,6 +320,7 @@ call nid proc@(Closure (Static label) _) = do
312 CallReply a <- expect
320 CallReply a <- expect
313 return a
321 return a
314
322
323+-- | Thrown by 'terminate'
315data ProcessTerminationException = ProcessTerminationException
324data ProcessTerminationException = ProcessTerminationException
316 deriving (Show, Typeable)
325 deriving (Show, Typeable)
317
326