Safe Haskell | None |
---|---|
Language | Haskell2010 |
Erlang style processes with message passing concurrency based on
(more) extensible-effects
.
This module re-exports most of the library.
There are several scheduler implementations to choose from.
This module re-exports Control.Eff.Concurrent.Process.ForkIOScheduler.
To use another scheduler implementation, don't import this module, but instead import one of:
Synopsis
- newtype ProcessId = ProcessId {}
- data ProcessDown = ProcessDown {}
- data MonitorReference = MonitorReference {}
- data SomeExitReason where
- SomeExitReason :: Interrupt x -> SomeExitReason
- type Interrupts = Exc (Interrupt Recoverable)
- type SafeProcesses r = Process r ': r
- type Processes e = Interrupts ': SafeProcesses e
- type RecoverableInterrupt = Interrupt Recoverable
- data Interrupt (t :: ExitRecovery) where
- NormalExitRequested :: Interrupt Recoverable
- OtherProcessNotRunning :: ProcessId -> Interrupt Recoverable
- TimeoutInterrupt :: String -> Interrupt Recoverable
- LinkedProcessCrashed :: ProcessId -> Interrupt Recoverable
- ErrorInterrupt :: String -> Interrupt Recoverable
- ExitNormally :: Interrupt NoRecovery
- ExitUnhandledError :: Text -> Interrupt NoRecovery
- ExitProcessCancelled :: Interrupt NoRecovery
- data ExitSeverity
- = NormalExit
- | Crash
- data ExitRecovery
- data ProcessState
- = ProcessBooting
- | ProcessIdle
- | ProcessBusy
- | ProcessBusyUpdatingDetails
- | ProcessBusySending
- | ProcessBusySendingShutdown
- | ProcessBusySendingInterrupt
- | ProcessBusyReceiving
- | ProcessBusyLinking
- | ProcessBusyUnlinking
- | ProcessBusyMonitoring
- | ProcessBusyDemonitoring
- | ProcessInterrupted
- | ProcessShuttingDown
- data MessageSelector a
- data ResumeProcess v where
- Interrupted :: Interrupt Recoverable -> ResumeProcess v
- ResumeWith :: a -> ResumeProcess a
- newtype Serializer message = MkSerializer {
- runSerializer :: message -> StrictDynamic
- data StrictDynamic
- newtype ProcessDetails = MkProcessDetails {}
- newtype ProcessTitle = MkProcessTitle {}
- data Process (r :: [Type -> Type]) b where
- FlushMessages :: Process r (ResumeProcess [StrictDynamic])
- YieldProcess :: Process r (ResumeProcess ())
- SelfPid :: Process r (ResumeProcess ProcessId)
- Spawn :: ProcessTitle -> Eff (Process r ': r) () -> Process r (ResumeProcess ProcessId)
- SpawnLink :: ProcessTitle -> Eff (Process r ': r) () -> Process r (ResumeProcess ProcessId)
- Shutdown :: Interrupt NoRecovery -> Process r a
- SendShutdown :: ProcessId -> Interrupt NoRecovery -> Process r (ResumeProcess ())
- SendInterrupt :: ProcessId -> Interrupt Recoverable -> Process r (ResumeProcess ())
- SendMessage :: ProcessId -> StrictDynamic -> Process r (ResumeProcess ())
- ReceiveSelectedMessage :: forall r a. MessageSelector a -> Process r (ResumeProcess a)
- MakeReference :: Process r (ResumeProcess Int)
- Monitor :: ProcessId -> Process r (ResumeProcess MonitorReference)
- Demonitor :: MonitorReference -> Process r (ResumeProcess ())
- Link :: ProcessId -> Process r (ResumeProcess ())
- Unlink :: ProcessId -> Process r (ResumeProcess ())
- UpdateProcessDetails :: ProcessDetails -> Process r (ResumeProcess ())
- GetProcessState :: ProcessId -> Process r (ResumeProcess (Maybe (ProcessTitle, ProcessDetails, ProcessState)))
- fromProcessTitle :: Lens' ProcessTitle Text
- fromProcessDetails :: Lens' ProcessDetails Text
- toStrictDynamic :: (Typeable a, NFData a) => a -> StrictDynamic
- fromStrictDynamic :: Typeable a => StrictDynamic -> Maybe a
- unwrapStrictDynamic :: StrictDynamic -> Dynamic
- selectMessage :: Typeable t => MessageSelector t
- filterMessage :: Typeable a => (a -> Bool) -> MessageSelector a
- selectMessageWith :: Typeable a => (a -> Maybe b) -> MessageSelector b
- selectDynamicMessage :: (StrictDynamic -> Maybe a) -> MessageSelector a
- selectAnyMessage :: MessageSelector StrictDynamic
- toExitRecovery :: Interrupt r -> ExitRecovery
- toExitSeverity :: Interrupt e -> ExitSeverity
- interruptToExit :: Interrupt Recoverable -> Interrupt NoRecovery
- isProcessDownInterrupt :: Maybe ProcessId -> Interrupt r -> Bool
- provideInterruptsShutdown :: forall e a. Eff (Processes e) a -> Eff (SafeProcesses e) a
- handleInterrupts :: (HasCallStack, Member Interrupts r) => (Interrupt Recoverable -> Eff r a) -> Eff r a -> Eff r a
- tryUninterrupted :: (HasCallStack, Member Interrupts r) => Eff r a -> Eff r (Either (Interrupt Recoverable) a)
- logInterrupts :: forall r. (Member Logs r, HasCallStack, Member Interrupts r) => Eff r () -> Eff r ()
- exitOnInterrupt :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r) => Eff r a -> Eff r a
- provideInterrupts :: HasCallStack => Eff (Interrupts ': r) a -> Eff r (Either (Interrupt Recoverable) a)
- mergeEitherInterruptAndExitReason :: Either (Interrupt Recoverable) (Interrupt NoRecovery) -> Interrupt NoRecovery
- interrupt :: (HasCallStack, Member Interrupts r) => Interrupt Recoverable -> Eff r a
- isCrash :: Interrupt x -> Bool
- isRecoverable :: Interrupt x -> Bool
- fromSomeExitReason :: SomeExitReason -> Either (Interrupt NoRecovery) (Interrupt Recoverable)
- toCrashReason :: Interrupt x -> Maybe Text
- logProcessExit :: forall e x. (Member Logs e, HasCallStack) => Interrupt x -> Eff e ()
- executeAndResume :: forall q r v. (SetMember Process (Process q) r, HasCallStack) => Process q (ResumeProcess v) -> Eff r (Either (Interrupt Recoverable) v)
- executeAndResumeOrExit :: forall r q v. (SetMember Process (Process q) r, HasCallStack) => Process q (ResumeProcess v) -> Eff r v
- executeAndResumeOrThrow :: forall q r v. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => Process q (ResumeProcess v) -> Eff r v
- yieldProcess :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => Eff r ()
- sendMessage :: forall r q o. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o) => ProcessId -> o -> Eff r ()
- sendAnyMessage :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> StrictDynamic -> Eff r ()
- sendShutdown :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> Interrupt NoRecovery -> Eff r ()
- sendInterrupt :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> Interrupt Recoverable -> Eff r ()
- spawn :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r ProcessId
- spawn_ :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r ()
- spawnLink :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r ProcessId
- spawnRaw :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (SafeProcesses q) () -> Eff r ProcessId
- spawnRaw_ :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (SafeProcesses q) () -> Eff r ()
- isProcessAlive :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r Bool
- getProcessState :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r (Maybe (ProcessTitle, ProcessDetails, ProcessState))
- updateProcessDetails :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessDetails -> Eff r ()
- receiveAnyMessage :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r StrictDynamic
- receiveSelectedMessage :: forall r q a. (HasCallStack, Show a, SetMember Process (Process q) r, Member Interrupts r) => MessageSelector a -> Eff r a
- receiveMessage :: forall a r q. (HasCallStack, Typeable a, NFData a, Show a, SetMember Process (Process q) r, Member Interrupts r) => Eff r a
- flushMessages :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r [StrictDynamic]
- receiveSelectedLoop :: forall r q a endOfLoopResult. (SetMember Process (Process q) r, HasCallStack) => MessageSelector a -> (Either (Interrupt Recoverable) a -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult
- receiveAnyLoop :: forall r q endOfLoopResult. (SetMember Process (Process q) r, HasCallStack) => (Either (Interrupt Recoverable) StrictDynamic -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult
- receiveLoop :: forall r q a endOfLoopResult. (SetMember Process (Process q) r, HasCallStack, NFData a, Typeable a) => (Either (Interrupt Recoverable) a -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult
- self :: (HasCallStack, SetMember Process (Process q) r) => Eff r ProcessId
- makeReference :: (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r Int
- monitor :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r MonitorReference
- demonitor :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => MonitorReference -> Eff r ()
- withMonitor :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> (MonitorReference -> Eff r a) -> Eff r a
- receiveWithMonitor :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r, Member Interrupts r, Typeable a, Show a) => ProcessId -> MessageSelector a -> Eff r (Either ProcessDown a)
- becauseProcessIsDown :: ProcessDown -> Interrupt Recoverable
- selectProcessDown :: MonitorReference -> MessageSelector ProcessDown
- linkProcess :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r ()
- unlinkProcess :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r ()
- exitBecause :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => Interrupt NoRecovery -> Eff r a
- exitNormally :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => Eff r a
- exitWithError :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => String -> Eff r a
- fromProcessId :: Iso' ProcessId Int
- type BaseEffects = Reader SchedulerState ': LoggingAndIo
- type HasBaseEffects r = (HasCallStack, Lifted IO r, BaseEffects <:: r)
- type Effects = Processes BaseEffects
- type SafeEffects = SafeProcesses BaseEffects
- defaultMain :: HasCallStack => Eff Effects () -> IO ()
- defaultMainWithLogWriter :: HasCallStack => LogWriter IO -> Eff Effects () -> IO ()
- schedule :: HasCallStack => Eff Effects () -> Eff LoggingAndIo ()
- data TimerElapsed
- data TimerReference
- data Timeout
- receiveAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Typeable a, NFData a, Show a) => Timeout -> Eff r (Maybe a)
- receiveSelectedAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Show a) => MessageSelector a -> Timeout -> Eff r (Either TimerElapsed a)
- receiveSelectedWithMonitorAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Show a) => ProcessId -> MessageSelector a -> Timeout -> Eff r (Either (Either ProcessDown TimerElapsed) a)
- selectTimerElapsed :: TimerReference -> MessageSelector TimerElapsed
- sendAfter :: forall r q message. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Typeable message, NFData message) => ProcessId -> Timeout -> (TimerReference -> message) -> Eff r TimerReference
- startTimer :: forall r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Timeout -> Eff r TimerReference
- cancelTimer :: forall r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => TimerReference -> Eff r ()
- newtype Endpoint protocol = Endpoint {}
- type family ProtocolReply (s :: Synchronicity) where ...
- data Synchronicity
- type TangiblePdu p r = (Typeable p, Typeable r, Tangible (Pdu p r))
- type Tangible i = (NFData i, Typeable i, Show i)
- class (NFData (Pdu protocol reply), Show (Pdu protocol reply), Typeable protocol, Typeable reply) => IsPdu (protocol :: Type) (reply :: Synchronicity) where
- data Pdu protocol reply
- deserializePdu :: Dynamic -> Maybe (Pdu protocol reply)
- class EmbedProtocol protocol embeddedProtocol where
- fromEndpoint :: forall protocol protocol. Iso (Endpoint protocol) (Endpoint protocol) ProcessId ProcessId
- proxyAsEndpoint :: proxy protocol -> ProcessId -> Endpoint protocol
- asEndpoint :: forall protocol. ProcessId -> Endpoint protocol
- toEmbeddedEndpoint :: forall inner outer. EmbedProtocol outer inner => Endpoint outer -> Endpoint inner
- fromEmbeddedEndpoint :: forall outer inner. EmbedProtocol outer inner => Endpoint inner -> Endpoint outer
- type EndpointReader o = Reader (Endpoint o)
- type ServesProtocol o r q = (Typeable o, SetMember Process (Process q) r, Member (EndpointReader o) r)
- cast :: forall o' o r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r, IsPdu o' Asynchronous, IsPdu o Asynchronous, EmbedProtocol o' o) => Endpoint o' -> Pdu o Asynchronous -> Eff r ()
- call :: forall result protocol' protocol r q. (SetMember Process (Process q) r, Member Interrupts r, TangiblePdu protocol' (Synchronous result), TangiblePdu protocol (Synchronous result), EmbedProtocol protocol' protocol, Tangible result, HasCallStack) => Endpoint protocol' -> Pdu protocol (Synchronous result) -> Eff r result
- callWithTimeout :: forall result protocol' protocol r q. (SetMember Process (Process q) r, Member Interrupts r, TangiblePdu protocol' (Synchronous result), TangiblePdu protocol (Synchronous result), EmbedProtocol protocol' protocol, Tangible result, Member Logs r, Lifted IO q, Lifted IO r, HasCallStack) => Endpoint protocol' -> Pdu protocol (Synchronous result) -> Timeout -> Eff r result
- runEndpointReader :: HasCallStack => Endpoint o -> Eff (EndpointReader o ': r) a -> Eff r a
- askEndpoint :: Member (EndpointReader o) e => Eff e (Endpoint o)
- callEndpointReader :: forall reply o r q. (ServesProtocol o r q, HasCallStack, Tangible reply, TangiblePdu o (Synchronous reply), Member Interrupts r) => Pdu o (Synchronous reply) -> Eff r reply
- castEndpointReader :: forall o r q. (ServesProtocol o r q, HasCallStack, Member Interrupts r, IsPdu o Asynchronous) => Pdu o Asynchronous -> Eff r ()
- callSingleton :: forall outer inner reply q e. (HasCallStack, EmbedProtocol outer inner, Member (EndpointReader outer) e, SetMember Process (Process q) e, Member Interrupts e, TangiblePdu outer (Synchronous reply), TangiblePdu inner (Synchronous reply), Tangible reply) => Pdu inner (Synchronous reply) -> Eff e reply
- castSingleton :: forall outer inner q e. (HasCallStack, EmbedProtocol outer inner, Member (EndpointReader outer) e, SetMember Process (Process q) e, Member Interrupts e, IsPdu outer Asynchronous, IsPdu inner Asynchronous) => Pdu inner Asynchronous -> Eff e ()
- newtype ReplyTarget p r = MkReplyTarget (Arg (RequestOrigin p r) (Serializer (Reply p r)))
- data RequestOrigin (proto :: Type) reply = RequestOrigin {}
- data Reply protocol reply where
- data Request protocol where
- Call :: forall protocol reply. (Tangible reply, TangiblePdu protocol (Synchronous reply)) => RequestOrigin protocol reply -> Pdu protocol (Synchronous reply) -> Request protocol
- Cast :: forall protocol. (TangiblePdu protocol Asynchronous, NFData (Pdu protocol Asynchronous)) => Pdu protocol Asynchronous -> Request protocol
- makeRequestOrigin :: (Typeable r, NFData r, SetMember Process (Process q0) e, '[Interrupts] <:: e) => Eff e (RequestOrigin p r)
- toEmbeddedOrigin :: forall outer inner reply. EmbedProtocol outer inner => RequestOrigin outer reply -> RequestOrigin inner reply
- embedRequestOrigin :: forall outer inner reply. EmbedProtocol outer inner => RequestOrigin inner reply -> RequestOrigin outer reply
- embedReplySerializer :: forall outer inner reply. EmbedProtocol outer inner => Serializer (Reply outer reply) -> Serializer (Reply inner reply)
- sendReply :: (SetMember Process (Process q) eff, Member Interrupts eff, Tangible reply, Typeable protocol) => ReplyTarget protocol reply -> reply -> Eff eff ()
- replyTarget :: Serializer (Reply p reply) -> RequestOrigin p reply -> ReplyTarget p reply
- replyTargetOrigin :: Lens' (ReplyTarget p reply) (RequestOrigin p reply)
- replyTargetSerializer :: Lens' (ReplyTarget p reply) (Serializer (Reply p reply))
- embeddedReplyTarget :: EmbedProtocol outer inner => Serializer (Reply outer reply) -> RequestOrigin outer reply -> ReplyTarget inner reply
- toEmbeddedReplyTarget :: EmbedProtocol outer inner => ReplyTarget outer r -> ReplyTarget inner r
- data family Pdu protocol reply
- type ObserverState o = State (Observers o)
- data Observers o
- data ObserverRegistry (o :: Type)
- data Observer o where
- registerObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, TangibleObserver o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r ()
- forgetObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r ()
- handleObservations :: (HasCallStack, Typeable o, SetMember Process (Process q) r, NFData (Observer o)) => (o -> Eff r ()) -> Pdu (Observer o) Asynchronous -> Eff r ()
- toObserver :: forall o p. (IsPdu p Asynchronous, EmbedProtocol p (Observer o), TangibleObserver o) => Endpoint p -> Observer o
- toObserverFor :: (TangibleObserver o, Typeable a, IsPdu a Asynchronous) => (o -> Pdu a Asynchronous) -> Endpoint a -> Observer o
- handleObserverRegistration :: forall o q r. (HasCallStack, Typeable o, SetMember Process (Process q) r, Member (ObserverState o) r, Member Logs r) => Pdu (ObserverRegistry o) Asynchronous -> Eff r ()
- manageObservers :: Eff (ObserverState o ': r) a -> Eff r a
- emptyObservers :: Observers o
- observed :: forall o r q. (SetMember Process (Process q) r, Member (ObserverState o) r, Member Interrupts r, TangibleObserver o) => o -> Eff r ()
- type ObservationQueueReader a = Reader (ObservationQueue a)
- data ObservationQueue a
- readObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r o
- tryReadObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r (Maybe o)
- flushObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r [o]
- withObservationQueue :: forall o b e len. (HasCallStack, Typeable o, Show o, Member Logs e, Lifted IO e, Integral len, Member Interrupts e) => len -> Eff (ObservationQueueReader o ': e) b -> Eff e b
- spawnLinkObservationQueueWriter :: forall o q h. (TangibleObserver o, IsPdu (Observer o) Asynchronous, Member Logs q, Lifted IO q, LogsTo h (Processes q), HasCallStack) => ObservationQueue o -> Eff (Processes q) (Observer o)
- module Control.Eff.Log
- module Control.Eff.LogWriter.Async
- module Control.Eff.LogWriter.Console
- module Control.Eff.LogWriter.File
- module Control.Eff.LogWriter.UDP
- module Control.Eff.LogWriter.Capture
- module Control.Eff.LogWriter.DebugTrace
- module Control.Eff.LogWriter.IO
- module Control.Eff.LogWriter.UnixSocket
- module Control.Eff.Loop
Concurrent Processes with Message Passing Concurrency
Each process is identified by a single process id, that stays constant throughout the life cycle of a process. Also, message sending relies on these values to address messages to processes.
Instances
Bounded ProcessId Source # | |
Enum ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process succ :: ProcessId -> ProcessId # pred :: ProcessId -> ProcessId # fromEnum :: ProcessId -> Int # enumFrom :: ProcessId -> [ProcessId] # enumFromThen :: ProcessId -> ProcessId -> [ProcessId] # enumFromTo :: ProcessId -> ProcessId -> [ProcessId] # enumFromThenTo :: ProcessId -> ProcessId -> ProcessId -> [ProcessId] # | |
Eq ProcessId Source # | |
Integral ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process | |
Num ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process | |
Ord ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process | |
Read ProcessId Source # | |
Real ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process toRational :: ProcessId -> Rational # | |
Show ProcessId Source # | |
NFData ProcessId Source # | |
Defined in Control.Eff.Concurrent.Process |
data ProcessDown Source #
A monitored process exited. This message is sent to a process by the scheduler, when a process that was monitored died.
Since: 0.12.0
Instances
data MonitorReference Source #
A value that contains a unique reference of a process monitoring.
Since: 0.12.0
Instances
data SomeExitReason where Source #
An existential wrapper around Interrupt
SomeExitReason :: Interrupt x -> SomeExitReason |
Instances
Eq SomeExitReason Source # | |
Defined in Control.Eff.Concurrent.Process (==) :: SomeExitReason -> SomeExitReason -> Bool # (/=) :: SomeExitReason -> SomeExitReason -> Bool # | |
Ord SomeExitReason Source # | |
Defined in Control.Eff.Concurrent.Process compare :: SomeExitReason -> SomeExitReason -> Ordering # (<) :: SomeExitReason -> SomeExitReason -> Bool # (<=) :: SomeExitReason -> SomeExitReason -> Bool # (>) :: SomeExitReason -> SomeExitReason -> Bool # (>=) :: SomeExitReason -> SomeExitReason -> Bool # max :: SomeExitReason -> SomeExitReason -> SomeExitReason # min :: SomeExitReason -> SomeExitReason -> SomeExitReason # | |
Show SomeExitReason Source # | |
Defined in Control.Eff.Concurrent.Process showsPrec :: Int -> SomeExitReason -> ShowS # show :: SomeExitReason -> String # showList :: [SomeExitReason] -> ShowS # | |
NFData SomeExitReason Source # | |
Defined in Control.Eff.Concurrent.Process rnf :: SomeExitReason -> () # |
type Interrupts = Exc (Interrupt Recoverable) Source #
Exc
eptions containing Interrupt
s.
See handleInterrupts
, exitOnInterrupt
or provideInterrupts
type SafeProcesses r = Process r ': r Source #
Cons Process
onto a list of effects. This is called SafeProcesses
because
the the actions cannot be interrupted in.
type Processes e = Interrupts ': SafeProcesses e Source #
This adds a layer of the Interrupts
effect on top of Processes
type RecoverableInterrupt = Interrupt Recoverable Source #
Interrupt
s which are Recoverable
.
data Interrupt (t :: ExitRecovery) where Source #
A sum-type with reasons for why a process operation, such as receiving messages, is interrupted in the scheduling loop.
This includes errors, that can occur when scheduling messages.
Since: 0.23.0
NormalExitRequested :: Interrupt Recoverable | A process has finished a unit of work and might exit or work on
something else. This is primarily used for interrupting infinite
server loops, allowing for additional cleanup work before
exiting (e.g. with Since: 0.13.2 |
OtherProcessNotRunning :: ProcessId -> Interrupt Recoverable | A process that should be running was not running. |
TimeoutInterrupt :: String -> Interrupt Recoverable | A |
LinkedProcessCrashed :: ProcessId -> Interrupt Recoverable | A linked process is down |
ErrorInterrupt :: String -> Interrupt Recoverable | An exit reason that has an error message and is |
ExitNormally :: Interrupt NoRecovery | A process function returned or exited without any error. |
ExitUnhandledError :: Text -> Interrupt NoRecovery | An error causes the process to exit immediately.
For example an unexpected runtime exception was thrown, i.e. an exception
derived from |
ExitProcessCancelled :: Interrupt NoRecovery | A process shall exit immediately, without any cleanup was cancelled (e.g. killed, in |
Instances
data ExitSeverity Source #
This value indicates whether a process exited in way consistent with the planned behaviour or not.
Instances
data ExitRecovery Source #
This kind is used to indicate if a Interrupt
can be treated like
a short interrupt which can be handled or ignored.
Instances
data ProcessState Source #
The state that a Process
is currently in.
ProcessBooting | The process has just been started but not scheduled yet. |
ProcessIdle | The process yielded it's time slice |
ProcessBusy | The process is busy with non-blocking |
ProcessBusyUpdatingDetails | The process is busy with |
ProcessBusySending | The process is busy with sending a message |
ProcessBusySendingShutdown | The process is busy with killing |
ProcessBusySendingInterrupt | The process is busy with killing |
ProcessBusyReceiving | The process blocked by a |
ProcessBusyLinking | The process blocked by a |
ProcessBusyUnlinking | The process blocked by a |
ProcessBusyMonitoring | The process blocked by a |
ProcessBusyDemonitoring | The process blocked by a |
ProcessInterrupted | The process was interrupted |
ProcessShuttingDown | The process was shutdown or crashed |
Instances
data MessageSelector a Source #
A function that decided if the next message will be received by
ReceiveSelectedMessage
. It conveniently is an instance of
Alternative
so the message selector can be combined:
>
> selectInt :: MessageSelector Int
> selectInt = selectMessage
>
> selectString :: MessageSelector String
> selectString = selectMessage
>
> selectIntOrString :: MessageSelector (Either Int String)
> selectIntOrString =
> Left $ selectTimeout| Right $ selectString
Instances
data ResumeProcess v where Source #
Every Process
action returns it's actual result wrapped in this type. It
will allow to signal errors as well as pass on normal results such as
incoming messages.
Interrupted :: Interrupt Recoverable -> ResumeProcess v | The current operation of the process was interrupted with a
|
ResumeWith :: a -> ResumeProcess a | The process may resume to do work, using the given result. |
Instances
newtype Serializer message Source #
Serialize a message
into a StrictDynamic
value to be sent via sendAnyMessage
.
This indirection allows, among other things, the composition of
Server
s.
Since: 0.24.1
MkSerializer | |
|
Instances
Contravariant Serializer Source # | |
Defined in Control.Eff.Concurrent.Process contramap :: (a -> b) -> Serializer b -> Serializer a # (>$) :: b -> Serializer b -> Serializer a # |
data StrictDynamic Source #
Data flows between Process
es via these messages.
This is just a newtype wrapper around Dynamic
.
The reason this type exists is to force construction through the code in this
module, which always evaluates a message to normal form before
sending it to another process.
Since: 0.22.0
Instances
Show StrictDynamic Source # | |
Defined in Control.Eff.Concurrent.Process showsPrec :: Int -> StrictDynamic -> ShowS # show :: StrictDynamic -> String # showList :: [StrictDynamic] -> ShowS # | |
NFData StrictDynamic Source # | |
Defined in Control.Eff.Concurrent.Process rnf :: StrictDynamic -> () # |
newtype ProcessDetails Source #
A multi-line text describing the current state of a process for debugging purposes.
Since: 0.24.1
Instances
newtype ProcessTitle Source #
A short title for a Process
for logging purposes.
Since: 0.24.1
Instances
data Process (r :: [Type -> Type]) b where Source #
The process effect is the basis for message passing concurrency. This effect describes an interface for concurrent, communicating isolated processes identified uniquely by a process-id.
Processes can raise exceptions that can be caught, exit gracefully or with an error, or be killed by other processes, with the option of ignoring the shutdown request.
Process Scheduling is implemented in different modules. All scheduler implementations should follow some basic rules:
- fair scheduling
- sending a message does not block
- receiving a message does block
- spawning a child blocks only a very moment
- a newly spawned process shall be scheduled before the parent process after
- the spawnRaw
- when the first process exists, all process should be killed immediately
FlushMessages :: Process r (ResumeProcess [StrictDynamic]) | Remove all messages from the process' message queue |
YieldProcess :: Process r (ResumeProcess ()) | In cooperative schedulers, this will give processing time to the scheduler. Every other operation implicitly serves the same purpose. Since: 0.12.0 |
SelfPid :: Process r (ResumeProcess ProcessId) | Return the current |
Spawn :: ProcessTitle -> Eff (Process r ': r) () -> Process r (ResumeProcess ProcessId) | Start a new process, the new process will execute an effect, the function
will return immediately with a |
SpawnLink :: ProcessTitle -> Eff (Process r ': r) () -> Process r (ResumeProcess ProcessId) | Start a new process, and Since: 0.12.0 |
Shutdown :: Interrupt NoRecovery -> Process r a | Shutdown the process; irregardless of the exit reason, this function never returns, |
SendShutdown :: ProcessId -> Interrupt NoRecovery -> Process r (ResumeProcess ()) | Shutdown another process immediately, the other process has no way of handling this! |
SendInterrupt :: ProcessId -> Interrupt Recoverable -> Process r (ResumeProcess ()) | Request that another a process interrupts. The targeted process is interrupted
and gets an |
SendMessage :: ProcessId -> StrictDynamic -> Process r (ResumeProcess ()) | Send a message to a process addressed by the |
ReceiveSelectedMessage :: forall r a. MessageSelector a -> Process r (ResumeProcess a) | Receive a message that matches a criteria.
This should block until an a message was received. The message is returned
as a |
MakeReference :: Process r (ResumeProcess Int) | Generate a unique |
Monitor :: ProcessId -> Process r (ResumeProcess MonitorReference) | Monitor another process. When the monitored process exits a
Since: 0.12.0 |
Demonitor :: MonitorReference -> Process r (ResumeProcess ()) | Remove a monitor. Since: 0.12.0 |
Link :: ProcessId -> Process r (ResumeProcess ()) | Connect the calling process to another process, such that
if one of the processes crashes (i.e. Since: 0.12.0 |
Unlink :: ProcessId -> Process r (ResumeProcess ()) | Unlink the calling process from the other process. Since: 0.12.0 |
UpdateProcessDetails :: ProcessDetails -> Process r (ResumeProcess ()) | Update the |
GetProcessState :: ProcessId -> Process r (ResumeProcess (Maybe (ProcessTitle, ProcessDetails, ProcessState))) | Get the |
Instances
fromProcessTitle :: Lens' ProcessTitle Text Source #
An isomorphism lens for the ProcessTitle
Since: 0.24.1
fromProcessDetails :: Lens' ProcessDetails Text Source #
An isomorphism lens for the ProcessDetails
Since: 0.24.1
toStrictDynamic :: (Typeable a, NFData a) => a -> StrictDynamic Source #
Deeply evaluate the given value and wrap it into a StrictDynamic
.
Since: 0.22.0
fromStrictDynamic :: Typeable a => StrictDynamic -> Maybe a Source #
Convert a StrictDynamic
back to a value.
Since: 0.22.0
unwrapStrictDynamic :: StrictDynamic -> Dynamic Source #
Convert a StrictDynamic
back to an unwrapped Dynamic
.
Since: 0.22.0
selectMessage :: Typeable t => MessageSelector t Source #
Create a message selector for a value that can be obtained by fromStrictDynamic
.
Since: 0.9.1
filterMessage :: Typeable a => (a -> Bool) -> MessageSelector a Source #
Create a message selector from a predicate.
Since: 0.9.1
selectMessageWith :: Typeable a => (a -> Maybe b) -> MessageSelector b Source #
Select a message of type a
and apply the given function to it.
If the function returns Just
The ReceiveSelectedMessage
function will
return the result (sans Maybe
).
Since: 0.9.1
selectDynamicMessage :: (StrictDynamic -> Maybe a) -> MessageSelector a Source #
Create a message selector.
Since: 0.9.1
selectAnyMessage :: MessageSelector StrictDynamic Source #
Create a message selector that will match every message. This is lazy
because the result is not force
ed.
Since: 0.9.1
toExitRecovery :: Interrupt r -> ExitRecovery Source #
Get the ExitRecovery
toExitSeverity :: Interrupt e -> ExitSeverity Source #
Get the ExitSeverity
of a Interrupt
.
interruptToExit :: Interrupt Recoverable -> Interrupt NoRecovery Source #
Return either ExitNormally
or interruptToExit
from a Recoverable
Interrupt
;
If the Interrupt
is NormalExitRequested
then return ExitNormally
isProcessDownInterrupt :: Maybe ProcessId -> Interrupt r -> Bool Source #
A predicate for linked process crashes.
provideInterruptsShutdown :: forall e a. Eff (Processes e) a -> Eff (SafeProcesses e) a Source #
Handle all Interrupt
s of an Processes
by
wrapping them up in interruptToExit
and then do a process Shutdown
.
handleInterrupts :: (HasCallStack, Member Interrupts r) => (Interrupt Recoverable -> Eff r a) -> Eff r a -> Eff r a Source #
Handle Interrupt
s arising during process operations, e.g.
when a linked process crashes while we wait in a receiveSelectedMessage
via a call to interrupt
.
tryUninterrupted :: (HasCallStack, Member Interrupts r) => Eff r a -> Eff r (Either (Interrupt Recoverable) a) Source #
Like handleInterrupts
, but instead of passing the Interrupt
to a handler function, Either
is returned.
Since: 0.13.2
logInterrupts :: forall r. (Member Logs r, HasCallStack, Member Interrupts r) => Eff r () -> Eff r () Source #
Handle interrupts by logging them with logProcessExit
and otherwise
ignoring them.
exitOnInterrupt :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r) => Eff r a -> Eff r a Source #
Handle Interrupt
s arising during process operations, e.g.
when a linked process crashes while we wait in a receiveSelectedMessage
via a call to interrupt
.
provideInterrupts :: HasCallStack => Eff (Interrupts ': r) a -> Eff r (Either (Interrupt Recoverable) a) Source #
Handle Interrupt
s arising during process operations, e.g.
when a linked process crashes while we wait in a receiveSelectedMessage
via a call to interrupt
.
mergeEitherInterruptAndExitReason :: Either (Interrupt Recoverable) (Interrupt NoRecovery) -> Interrupt NoRecovery Source #
Wrap all (left) Interrupt
s into interruptToExit
and
return the (right) NoRecovery
Interrupt
s as is.
interrupt :: (HasCallStack, Member Interrupts r) => Interrupt Recoverable -> Eff r a Source #
Throw an Interrupt
, can be handled by handleInterrupts
or
exitOnInterrupt
or provideInterrupts
.
isCrash :: Interrupt x -> Bool Source #
A predicate for crashes. A crash happens when a process exits
with an Interrupt
other than ExitNormally
isRecoverable :: Interrupt x -> Bool Source #
A predicate for recoverable exit reasons. This predicate defines the
exit reasons which functions such as executeAndResume
fromSomeExitReason :: SomeExitReason -> Either (Interrupt NoRecovery) (Interrupt Recoverable) Source #
Partition a SomeExitReason
back into either a NoRecovery
or a Recoverable
Interrupt
toCrashReason :: Interrupt x -> Maybe Text Source #
Print a Interrupt
to Just
a formatted String
when isCrash
is True
.
This can be useful in combination with view patterns, e.g.:
logCrash :: Interrupt -> Eff e () logCrash (toCrashReason -> Just reason) = logError reason logCrash _ = return ()
Though this can be improved to:
logCrash = traverse_ logError . toCrashReason
logProcessExit :: forall e x. (Member Logs e, HasCallStack) => Interrupt x -> Eff e () Source #
Log the Interrupt
s
executeAndResume :: forall q r v. (SetMember Process (Process q) r, HasCallStack) => Process q (ResumeProcess v) -> Eff r (Either (Interrupt Recoverable) v) Source #
Execute a and action and return the result;
if the process is interrupted by an error or exception, or an explicit
shutdown from another process, or through a crash of a linked process, i.e.
whenever the exit reason satisfies isRecoverable
, return the exit reason.
executeAndResumeOrExit :: forall r q v. (SetMember Process (Process q) r, HasCallStack) => Process q (ResumeProcess v) -> Eff r v Source #
Execute a Process
action and resume the process, exit
the process when an Interrupts
was raised. Use executeAndResume
to catch
interrupts.
executeAndResumeOrThrow :: forall q r v. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => Process q (ResumeProcess v) -> Eff r v Source #
Execute a Process
action and resume the process, exit
the process when an Interrupts
was raised. Use executeAndResume
to catch
interrupts.
yieldProcess :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => Eff r () Source #
Use executeAndResumeOrExit
to execute YieldProcess
. Refer to YieldProcess
for more information.
sendMessage :: forall r q o. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o) => ProcessId -> o -> Eff r () Source #
Send a message to a process addressed by the ProcessId
.
See SendMessage
.
The message will be reduced to normal form (rnf
) by/in the caller process.
sendAnyMessage :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> StrictDynamic -> Eff r () Source #
Send a Dynamic
value to a process addressed by the ProcessId
.
See SendMessage
.
sendShutdown :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> Interrupt NoRecovery -> Eff r () Source #
Exit a process addressed by the ProcessId
. The process will exit,
it might do some cleanup, but is ultimately unrecoverable.
See SendShutdown
.
sendInterrupt :: forall r q. (SetMember Process (Process q) r, HasCallStack, Member Interrupts r) => ProcessId -> Interrupt Recoverable -> Eff r () Source #
Interrupts a process addressed by the ProcessId
. The process might exit,
or it may continue.
| Like sendInterrupt
, but also return True
iff the process to exit exists.
spawn :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r ProcessId Source #
Start a new process, the new process will execute an effect, the function
will return immediately with a ProcessId
. If the new process is
interrupted, the process will Shutdown
with the Interrupt
wrapped in interruptToExit
. For specific use cases it might be better to use
spawnRaw
.
spawn_ :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r () Source #
Like spawn
but return ()
.
spawnLink :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (Processes q) () -> Eff r ProcessId Source #
Start a new process, and immediately link to it.
Since: 0.12.0
spawnRaw :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (SafeProcesses q) () -> Eff r ProcessId Source #
Start a new process, the new process will execute an effect, the function
will return immediately with a ProcessId
. The spawned process has only the
raw SafeProcesses
effects. For non-library code spawn
might be better
suited.
spawnRaw_ :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessTitle -> Eff (SafeProcesses q) () -> Eff r () Source #
Like spawnRaw
but return ()
.
isProcessAlive :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r Bool Source #
Return True
if the process is alive.
Since: 0.12.0
getProcessState :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r (Maybe (ProcessTitle, ProcessDetails, ProcessState)) Source #
Return the ProcessTitle
, ProcessDetails
and ProcessState
,
for the given process, if the process is alive.
Since: 0.24.1
updateProcessDetails :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessDetails -> Eff r () Source #
Replace the ProcessDetails
of the process.
Since: 0.24.1
receiveAnyMessage :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r StrictDynamic Source #
Block until a message was received.
See ReceiveSelectedMessage
for more documentation.
receiveSelectedMessage :: forall r q a. (HasCallStack, Show a, SetMember Process (Process q) r, Member Interrupts r) => MessageSelector a -> Eff r a Source #
Block until a message was received, that is not Nothing
after applying
a callback to it.
See ReceiveSelectedMessage
for more documentation.
receiveMessage :: forall a r q. (HasCallStack, Typeable a, NFData a, Show a, SetMember Process (Process q) r, Member Interrupts r) => Eff r a Source #
Receive and cast the message to some Typeable
instance.
See ReceiveSelectedMessage
for more documentation.
This will wait for a message of the return type using receiveSelectedMessage
flushMessages :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r [StrictDynamic] Source #
Remove and return all messages currently enqueued in the process message queue.
Since: 0.12.0
receiveSelectedLoop :: forall r q a endOfLoopResult. (SetMember Process (Process q) r, HasCallStack) => MessageSelector a -> (Either (Interrupt Recoverable) a -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult Source #
Enter a loop to receive messages and pass them to a callback, until the
function returns Just
a result.
Only the messages of the given type will be received.
If the process is interrupted by an exception of by a SendShutdown
from
another process, with an exit reason that satisfies isRecoverable
, then
the callback will be invoked with
, otherwise the
process will be exited with the same reason using Left
Interrupt
exitBecause
.
See also ReceiveSelectedMessage
for more documentation.
receiveAnyLoop :: forall r q endOfLoopResult. (SetMember Process (Process q) r, HasCallStack) => (Either (Interrupt Recoverable) StrictDynamic -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult Source #
Like receiveSelectedLoop
but not selective.
See also selectAnyMessage
, receiveSelectedLoop
.
receiveLoop :: forall r q a endOfLoopResult. (SetMember Process (Process q) r, HasCallStack, NFData a, Typeable a) => (Either (Interrupt Recoverable) a -> Eff r (Maybe endOfLoopResult)) -> Eff r endOfLoopResult Source #
Like receiveSelectedLoop
but refined to casting to a specific Typeable
using selectMessage
.
self :: (HasCallStack, SetMember Process (Process q) r) => Eff r ProcessId Source #
Returns the ProcessId
of the current process.
makeReference :: (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Eff r Int Source #
Generate a unique Int
for the current process.
monitor :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r MonitorReference Source #
Monitor another process. When the monitored process exits a
ProcessDown
is sent to the calling process.
The return value is a unique identifier for that monitor.
There can be multiple monitors on the same process,
and a message for each will be sent.
If the process is already dead, the ProcessDown
message
will be sent immediately, without exit reason
Since: 0.12.0
demonitor :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => MonitorReference -> Eff r () Source #
Remove a monitor created with monitor
.
Since: 0.12.0
withMonitor :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> (MonitorReference -> Eff r a) -> Eff r a Source #
receiveWithMonitor :: (HasCallStack, Member Interrupts r, SetMember Process (Process q) r, Member Interrupts r, Typeable a, Show a) => ProcessId -> MessageSelector a -> Eff r (Either ProcessDown a) Source #
A MessageSelector
for receiving either a monitor of the
given process or another message.
Since: 0.12.0
becauseProcessIsDown :: ProcessDown -> Interrupt Recoverable Source #
Make an Interrupt
for a ProcessDown
message.
For example: doSomething >>= either (interrupt . becauseProcessIsDown) return
Since: 0.12.0
selectProcessDown :: MonitorReference -> MessageSelector ProcessDown Source #
A MessageSelector
for the ProcessDown
message of a specific
process.
Since: 0.12.0
linkProcess :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r () Source #
Connect the calling process to another process, such that
if one of the processes crashes (i.e. isCrash
returns True
), the other
is shutdown with the Interrupt
LinkedProcessCrashed
.
Since: 0.12.0
unlinkProcess :: forall r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => ProcessId -> Eff r () Source #
Unlink the calling process from the other process.
Since: 0.12.0
exitBecause :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => Interrupt NoRecovery -> Eff r a Source #
Exit the process with a Interrupt
.
exitNormally :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => Eff r a Source #
Exit the process.
exitWithError :: forall r q a. (HasCallStack, SetMember Process (Process q) r) => String -> Eff r a Source #
Exit the process with an error.
Scheduler Process Effect Handler
Concurrent Scheduler
type BaseEffects = Reader SchedulerState ': LoggingAndIo Source #
The concrete list of Eff
ects for this scheduler implementation.
Since: 0.25.0
type HasBaseEffects r = (HasCallStack, Lifted IO r, BaseEffects <:: r) Source #
Type class constraint to indicate that an effect union contains the effects required by every process and the scheduler implementation itself.
Since: 0.25.0
type Effects = Processes BaseEffects Source #
The Eff
ects for interruptable, concurrent processes, scheduled via forkIO
.
Since: 0.25.0
type SafeEffects = SafeProcesses BaseEffects Source #
The concrete list of Eff
ects of processes compatible with this scheduler.
This builds upon BaseEffects
.
Since: 0.25.0
defaultMain :: HasCallStack => Eff Effects () -> IO () Source #
Start the message passing concurrency system then execute a Process
on
top of BaseEffects
effect. All logging is sent to standard output.
defaultMainWithLogWriter :: HasCallStack => LogWriter IO -> Eff Effects () -> IO () Source #
Start the message passing concurrency system then execute a Process
on
top of BaseEffects
effect. All logging is sent to standard output.
schedule :: HasCallStack => Eff Effects () -> Eff LoggingAndIo () Source #
This is the main entry point to running a message passing concurrency
application. This function takes a Process
on top of the BaseEffects
effect for concurrent logging.
Timers and Timeouts
data TimerElapsed Source #
A value to be sent when timer started with startTimer
has elapsed.
Since: 0.12.0
Instances
Eq TimerElapsed Source # | |
Defined in Control.Eff.Concurrent.Process.Timer (==) :: TimerElapsed -> TimerElapsed -> Bool # (/=) :: TimerElapsed -> TimerElapsed -> Bool # | |
Ord TimerElapsed Source # | |
Defined in Control.Eff.Concurrent.Process.Timer compare :: TimerElapsed -> TimerElapsed -> Ordering # (<) :: TimerElapsed -> TimerElapsed -> Bool # (<=) :: TimerElapsed -> TimerElapsed -> Bool # (>) :: TimerElapsed -> TimerElapsed -> Bool # (>=) :: TimerElapsed -> TimerElapsed -> Bool # max :: TimerElapsed -> TimerElapsed -> TimerElapsed # min :: TimerElapsed -> TimerElapsed -> TimerElapsed # | |
Show TimerElapsed Source # | |
Defined in Control.Eff.Concurrent.Process.Timer showsPrec :: Int -> TimerElapsed -> ShowS # show :: TimerElapsed -> String # showList :: [TimerElapsed] -> ShowS # | |
NFData TimerElapsed Source # | |
Defined in Control.Eff.Concurrent.Process.Timer rnf :: TimerElapsed -> () # |
data TimerReference Source #
The reference to a timer started by startTimer
, required to stop
a timer via cancelTimer
.
Since: 0.12.0
Instances
A number of micro seconds.
Since: 0.12.0
Instances
Enum Timeout Source # | |
Eq Timeout Source # | |
Integral Timeout Source # | |
Defined in Control.Eff.Concurrent.Process.Timer | |
Num Timeout Source # | |
Ord Timeout Source # | |
Defined in Control.Eff.Concurrent.Process.Timer | |
Real Timeout Source # | |
Defined in Control.Eff.Concurrent.Process.Timer toRational :: Timeout -> Rational # | |
Show Timeout Source # | |
NFData Timeout Source # | |
Defined in Control.Eff.Concurrent.Process.Timer |
receiveAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Typeable a, NFData a, Show a) => Timeout -> Eff r (Maybe a) Source #
Wait for a message of the given type for the given time. When no message
arrives in time, return Nothing
. This is based on
receiveSelectedAfter
.
Since: 0.12.0
receiveSelectedAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Show a) => MessageSelector a -> Timeout -> Eff r (Either TimerElapsed a) Source #
Wait for a message of the given type for the given time. When no message
arrives in time, return Left
TimerElapsed
. This is based on
selectTimerElapsed
and startTimer
.
Since: 0.12.0
receiveSelectedWithMonitorAfter :: forall a r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Show a) => ProcessId -> MessageSelector a -> Timeout -> Eff r (Either (Either ProcessDown TimerElapsed) a) Source #
Like receiveWithMonitor
combined with receiveSelectedAfter
.
Since: 0.22.0
selectTimerElapsed :: TimerReference -> MessageSelector TimerElapsed Source #
A MessageSelector
matching TimerElapsed
messages created by
startTimer
.
Since: 0.12.0
sendAfter :: forall r q message. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r, Typeable message, NFData message) => ProcessId -> Timeout -> (TimerReference -> message) -> Eff r TimerReference Source #
Send a message to a given process after waiting. The message is created by
applying the function parameter to the TimerReference
, such that the
message can directly refer to the timer.
Since: 0.12.0
startTimer :: forall r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => Timeout -> Eff r TimerReference Source #
Start a new timer, after the time has elapsed, TimerElapsed
is sent to
calling process. The message also contains the TimerReference
returned by
this function. Use cancelTimer
to cancel the timer. Use
selectTimerElapsed
to receive the message using receiveSelectedMessage
.
To receive messages with guarded with a timeout see receiveAfter
.
Since: 0.12.0
cancelTimer :: forall r q. (Lifted IO q, HasCallStack, SetMember Process (Process q) r, Member Interrupts r) => TimerReference -> Eff r () Source #
Cancel a timer started with startTimer
.
Since: 0.12.0
Data Types and Functions for APIs (aka Protocols)
newtype Endpoint protocol Source #
Instances
Eq (Endpoint protocol) Source # | |
Ord (Endpoint protocol) Source # | |
Defined in Control.Eff.Concurrent.Protocol compare :: Endpoint protocol -> Endpoint protocol -> Ordering # (<) :: Endpoint protocol -> Endpoint protocol -> Bool # (<=) :: Endpoint protocol -> Endpoint protocol -> Bool # (>) :: Endpoint protocol -> Endpoint protocol -> Bool # (>=) :: Endpoint protocol -> Endpoint protocol -> Bool # max :: Endpoint protocol -> Endpoint protocol -> Endpoint protocol # min :: Endpoint protocol -> Endpoint protocol -> Endpoint protocol # | |
Typeable protocol => Show (Endpoint protocol) Source # | |
NFData (Endpoint protocol) Source # | |
Defined in Control.Eff.Concurrent.Protocol | |
type ToPretty (Endpoint a :: Type) Source # | |
type family ProtocolReply (s :: Synchronicity) where ... Source #
This type function takes an Pdu
and analysis the reply type, i.e. the Synchronicity
and evaluates to either t
for an
Pdu x (
or to '()' for an Synchronous
t)Pdu x
.Asynchronous
Since: 0.24.0
ProtocolReply (Synchronous t) = t | |
ProtocolReply Asynchronous = () |
data Synchronicity Source #
The (promoted) constructors of this type specify (at the type level) the
reply behavior of a specific constructor of an Pdu
instance.
Synchronous Type | Specify that handling a request is a blocking operation
with a specific return type, e.g. |
Asynchronous | Non-blocking, asynchronous, request handling |
type TangiblePdu p r = (Typeable p, Typeable r, Tangible (Pdu p r)) Source #
A Constraint
that bundles the requirements for the
Pdu
values of a protocol.
This ensures that Pdu
s can be strictly and deeply evaluated and shown
such that for example logging is possible.
Since: 0.24.0
class (NFData (Pdu protocol reply), Show (Pdu protocol reply), Typeable protocol, Typeable reply) => IsPdu (protocol :: Type) (reply :: Synchronicity) where Source #
This data family defines the protocol data units (PDU) of a protocol.
A Protocol in the sense of a communication interface description between processes.
The first parameter is usually a user defined type that identifies the
protocol that uses the Pdu
s are. It maybe a phantom type.
The second parameter specifies if a specific constructor of an (GADT-like)
Pdu
instance is Synchronous
, i.e. returns a result and blocks the caller
or if it is Asynchronous
Example:
data BookShop deriving Typeable instance IsPdu BookShop r where data instance Pdu BookShop r where RentBook :: BookId -> Pdu BookShop ('Synchronous (Either RentalError RentalId)) BringBack :: RentalId -> Pdu BookShop 'Asynchronous deriving Typeable type BookId = Int type RentalId = Int type RentalError = String
Since: 0.25.1
Nothing
deserializePdu :: Dynamic -> Maybe (Pdu protocol reply) Source #
deserializePdu :: Typeable (Pdu protocol reply) => Dynamic -> Maybe (Pdu protocol reply) Source #
Instances
(NFData (Pdu (Sup p) r), Show (Pdu (Sup p) r), Typeable p, Typeable r) => IsPdu (Sup p) r Source # | |
(Typeable o, Typeable r) => IsPdu (ObserverRegistry o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (ObserverRegistry o) r :: Type Source # deserializePdu :: Dynamic -> Maybe (Pdu (ObserverRegistry o) r) Source # | |
(NFData o, Show o, Typeable o, Typeable r) => IsPdu (Observer o) r Source # | A minimal Protocol for handling observations.
This is one simple way of receiving observations - of course users can use
any other Since: 0.16.0 |
(IsPdu a1 r, IsPdu a2 r) => IsPdu (a1, a2) r Source # | |
(IsPdu a1 r, IsPdu a2 r, IsPdu a3 r) => IsPdu (a1, a2, a3) r Source # | |
(IsPdu a1 r, IsPdu a2 r, IsPdu a3 r, IsPdu a4 r) => IsPdu (a1, a2, a3, a4) r Source # | |
(IsPdu a1 r, IsPdu a2 r, IsPdu a3 r, IsPdu a4 r, IsPdu a5 r) => IsPdu (a1, a2, a3, a4, a5) r Source # | |
class EmbedProtocol protocol embeddedProtocol where Source #
A class for Pdu
instances that embed other Pdu
.
A Prism
for the embedded Pdu
is the center of this class
Laws: embeddedPdu = prism' embedPdu fromPdu
Since: 0.24.0
Nothing
embeddedPdu :: Prism' (Pdu protocol result) (Pdu embeddedProtocol result) Source #
embedPdu :: Pdu embeddedProtocol r -> Pdu protocol r Source #
fromPdu :: Pdu protocol r -> Maybe (Pdu embeddedProtocol r) Source #
Instances
EmbedProtocol a a Source # | |
EmbedProtocol (a1, a2) a2 Source # | |
EmbedProtocol (a1, a2) a1 Source # | |
EmbedProtocol (a1, a2, a3) a3 Source # | |
EmbedProtocol (a1, a2, a3) a2 Source # | |
EmbedProtocol (a1, a2, a3) a1 Source # | |
EmbedProtocol (a1, a2, a3, a4) a4 Source # | |
EmbedProtocol (a1, a2, a3, a4) a3 Source # | |
EmbedProtocol (a1, a2, a3, a4) a2 Source # | |
EmbedProtocol (a1, a2, a3, a4) a1 Source # | |
EmbedProtocol (a1, a2, a3, a4, a5) a5 Source # | |
EmbedProtocol (a1, a2, a3, a4, a5) a4 Source # | |
EmbedProtocol (a1, a2, a3, a4, a5) a3 Source # | |
EmbedProtocol (a1, a2, a3, a4, a5) a2 Source # | |
EmbedProtocol (a1, a2, a3, a4, a5) a1 Source # | |
fromEndpoint :: forall protocol protocol. Iso (Endpoint protocol) (Endpoint protocol) ProcessId ProcessId Source #
proxyAsEndpoint :: proxy protocol -> ProcessId -> Endpoint protocol Source #
asEndpoint :: forall protocol. ProcessId -> Endpoint protocol Source #
toEmbeddedEndpoint :: forall inner outer. EmbedProtocol outer inner => Endpoint outer -> Endpoint inner Source #
Convert an Endpoint
to an endpoint for an embedded protocol.
See EmbedProtocol
, fromEmbeddedEndpoint
.
Since: 0.25.1
fromEmbeddedEndpoint :: forall outer inner. EmbedProtocol outer inner => Endpoint inner -> Endpoint outer Source #
Convert an Endpoint
to an endpoint for a server, that embeds the protocol.
See EmbedProtocol
, toEmbeddedEndpoint
.
Since: 0.25.1
Client Functions for Consuming APIs
type EndpointReader o = Reader (Endpoint o) Source #
The reader effect for ProcessId
s for Pdu
s, see runEndpointReader
type ServesProtocol o r q = (Typeable o, SetMember Process (Process q) r, Member (EndpointReader o) r) Source #
cast :: forall o' o r q. (HasCallStack, SetMember Process (Process q) r, Member Interrupts r, IsPdu o' Asynchronous, IsPdu o Asynchronous, EmbedProtocol o' o) => Endpoint o' -> Pdu o Asynchronous -> Eff r () Source #
Send a request Pdu
that has no reply and return immediately.
The type signature enforces that the corresponding Pdu
clause is
Asynchronous
. The operation never fails, if it is important to know if the
message was delivered, use call
instead.
The message will be reduced to normal form (rnf
) in the caller process.
call :: forall result protocol' protocol r q. (SetMember Process (Process q) r, Member Interrupts r, TangiblePdu protocol' (Synchronous result), TangiblePdu protocol (Synchronous result), EmbedProtocol protocol' protocol, Tangible result, HasCallStack) => Endpoint protocol' -> Pdu protocol (Synchronous result) -> Eff r result Source #
Send a request Pdu
and wait for the server to return a result value.
The type signature enforces that the corresponding Pdu
clause is
Synchronous
.
Always prefer callWithTimeout
over call
callWithTimeout :: forall result protocol' protocol r q. (SetMember Process (Process q) r, Member Interrupts r, TangiblePdu protocol' (Synchronous result), TangiblePdu protocol (Synchronous result), EmbedProtocol protocol' protocol, Tangible result, Member Logs r, Lifted IO q, Lifted IO r, HasCallStack) => Endpoint protocol' -> Pdu protocol (Synchronous result) -> Timeout -> Eff r result Source #
Send an request Pdu
and wait for the server to return a result value.
The type signature enforces that the corresponding Pdu
clause is
Synchronous
.
If the server that was called dies, this function interrupts the
process with ProcessDown
.
If the server takes longer to reply than the given timeout, this
function interrupts the process with TimeoutInterrupt
.
Always prefer this function over call
Since: 0.22.0
runEndpointReader :: HasCallStack => Endpoint o -> Eff (EndpointReader o ': r) a -> Eff r a Source #
Run a reader effect that contains the one server handling a specific
Pdu
instance.
askEndpoint :: Member (EndpointReader o) e => Eff e (Endpoint o) Source #
Get the Endpoint
registered with runEndpointReader
.
callEndpointReader :: forall reply o r q. (ServesProtocol o r q, HasCallStack, Tangible reply, TangiblePdu o (Synchronous reply), Member Interrupts r) => Pdu o (Synchronous reply) -> Eff r reply Source #
Like call
but take the Endpoint
from the reader provided by
runEndpointReader
.
When working with an embedded Pdu
use callSingleton
.
castEndpointReader :: forall o r q. (ServesProtocol o r q, HasCallStack, Member Interrupts r, IsPdu o Asynchronous) => Pdu o Asynchronous -> Eff r () Source #
Like cast
but take the Endpoint
from the reader provided by
runEndpointReader
.
When working with an embedded Pdu
use castSingleton
.
callSingleton :: forall outer inner reply q e. (HasCallStack, EmbedProtocol outer inner, Member (EndpointReader outer) e, SetMember Process (Process q) e, Member Interrupts e, TangiblePdu outer (Synchronous reply), TangiblePdu inner (Synchronous reply), Tangible reply) => Pdu inner (Synchronous reply) -> Eff e reply Source #
Like callEndpointReader
, uses embedPdu
to embed the value.
This function makes use of AmbigousTypes and TypeApplications.
When not working with an embedded Pdu
use callEndpointReader
.
Since: 0.25.1
castSingleton :: forall outer inner q e. (HasCallStack, EmbedProtocol outer inner, Member (EndpointReader outer) e, SetMember Process (Process q) e, Member Interrupts e, IsPdu outer Asynchronous, IsPdu inner Asynchronous) => Pdu inner Asynchronous -> Eff e () Source #
Like castEndpointReader
, but uses embedPdu
to embed the value.
This function makes use of AmbigousTypes and TypeApplications.
When not working with an embedded Pdu
use castEndpointReader
.
Since: 0.25.1
Protocol-Server Support Functions for building protocol servers
newtype ReplyTarget p r Source #
Target of a Call
reply.
This combines a RequestOrigin
with a Serializer
for a Reply
using Arg
.
There are to smart constructors for this type: replyTarget
and embeddedReplyTarget
.
Because of Arg
the Eq
and Ord
instances are implemented via
the RequestOrigin
instances.
Since: 0.26.0
MkReplyTarget (Arg (RequestOrigin p r) (Serializer (Reply p r))) |
Instances
Eq (ReplyTarget p r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Request (==) :: ReplyTarget p r -> ReplyTarget p r -> Bool # (/=) :: ReplyTarget p r -> ReplyTarget p r -> Bool # | |
Ord (ReplyTarget p r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Request compare :: ReplyTarget p r -> ReplyTarget p r -> Ordering # (<) :: ReplyTarget p r -> ReplyTarget p r -> Bool # (<=) :: ReplyTarget p r -> ReplyTarget p r -> Bool # (>) :: ReplyTarget p r -> ReplyTarget p r -> Bool # (>=) :: ReplyTarget p r -> ReplyTarget p r -> Bool # max :: ReplyTarget p r -> ReplyTarget p r -> ReplyTarget p r # min :: ReplyTarget p r -> ReplyTarget p r -> ReplyTarget p r # | |
Show (ReplyTarget p r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Request showsPrec :: Int -> ReplyTarget p r -> ShowS # show :: ReplyTarget p r -> String # showList :: [ReplyTarget p r] -> ShowS # | |
NFData (ReplyTarget p r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Request rnf :: ReplyTarget p r -> () # |
data RequestOrigin (proto :: Type) reply Source #
Instances
data Reply protocol reply where Source #
The wrapper around replies to Call
s.
Since: 0.15.0
Reply | |
|
data Request protocol where Source #
A wrapper sum type for calls and casts for the Pdu
s of a protocol
Since: 0.15.0
Call :: forall protocol reply. (Tangible reply, TangiblePdu protocol (Synchronous reply)) => RequestOrigin protocol reply -> Pdu protocol (Synchronous reply) -> Request protocol | |
Cast :: forall protocol. (TangiblePdu protocol Asynchronous, NFData (Pdu protocol Asynchronous)) => Pdu protocol Asynchronous -> Request protocol |
makeRequestOrigin :: (Typeable r, NFData r, SetMember Process (Process q0) e, '[Interrupts] <:: e) => Eff e (RequestOrigin p r) Source #
Create a new, unique RequestOrigin
value for the current process.
Since: 0.24.0
toEmbeddedOrigin :: forall outer inner reply. EmbedProtocol outer inner => RequestOrigin outer reply -> RequestOrigin inner reply Source #
Turn an RequestOrigin
to an origin for an embedded request (See EmbedProtocol
).
This is useful of a server delegates the calls
and casts
for an embedded protocol
to functions, that require the Serializer
and RequestOrigin
in order to call
sendReply
.
See also embedReplySerializer
.
Since: 0.24.3
embedRequestOrigin :: forall outer inner reply. EmbedProtocol outer inner => RequestOrigin inner reply -> RequestOrigin outer reply Source #
Turn an embedded RequestOrigin
to a RequestOrigin
for the bigger request.
This is the inverse of toEmbeddedOrigin
.
This function is strict in all parameters.
Since: 0.24.2
embedReplySerializer :: forall outer inner reply. EmbedProtocol outer inner => Serializer (Reply outer reply) -> Serializer (Reply inner reply) Source #
Turn a Serializer
for a Pdu
instance that contains embedded Pdu
values
into a Reply
Serializer
for the embedded Pdu
.
This is useful of a server delegates the calls
and casts
for an embedded protocol
to functions, that require the Serializer
and RequestOrigin
in order to call
sendReply
.
See also toEmbeddedOrigin
.
Since: 0.24.2
sendReply :: (SetMember Process (Process q) eff, Member Interrupts eff, Tangible reply, Typeable protocol) => ReplyTarget protocol reply -> reply -> Eff eff () Source #
Answer a Call
by sending the reply value to the client process.
The ProcessId
, the RequestOrigin
and the Reply
Serializer
are
stored in the ReplyTarget
.
Since: 0.25.1
replyTarget :: Serializer (Reply p reply) -> RequestOrigin p reply -> ReplyTarget p reply Source #
Smart constructor for a ReplyTarget
.
To build a ReplyTarget
for an EmbedProtocol
instance use embeddedReplyTarget
.
Since: 0.26.0
replyTargetOrigin :: Lens' (ReplyTarget p reply) (RequestOrigin p reply) Source #
A simple Lens
for the RequestOrigin
of a ReplyTarget
.
Since: 0.26.0
replyTargetSerializer :: Lens' (ReplyTarget p reply) (Serializer (Reply p reply)) Source #
A simple Lens
for the Reply
Serializer
of a ReplyTarget
.
Since: 0.26.0
embeddedReplyTarget :: EmbedProtocol outer inner => Serializer (Reply outer reply) -> RequestOrigin outer reply -> ReplyTarget inner reply Source #
Smart constructor for an embedded ReplyTarget
.
This combines replyTarget
and toEmbeddedReplyTarget
.
Since: 0.26.0
toEmbeddedReplyTarget :: EmbedProtocol outer inner => ReplyTarget outer r -> ReplyTarget inner r Source #
Convert a ReplyTarget
to be usable for embedded replies.
This combines a toEmbeddedOrigin
with embedReplySerializer
to produce a
ReplyTarget
that can be passed to functions defined soley on an embedded protocol.
Since: 0.26.0
Observer Functions for Events and Event Listener
data family Pdu protocol reply Source #
The protocol data unit type for the given protocol.
Instances
type ObserverState o = State (Observers o) Source #
Alias for the effect that contains the observers managed by manageObservers
Internal state for manageObservers
Instances
Eq (Observers o) Source # | |
Ord (Observers o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
Show (Observers o) Source # | |
NFData o => NFData (Observers o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
data ObserverRegistry (o :: Type) Source #
A protocol for managing Observer
s, encompassing registration and de-registration of
Observer
s.
Since: 0.16.0
Instances
(Typeable o, Typeable r) => IsPdu (ObserverRegistry o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (ObserverRegistry o) r :: Type Source # deserializePdu :: Dynamic -> Maybe (Pdu (ObserverRegistry o) r) Source # | |
Show (Pdu (ObserverRegistry o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
NFData (Pdu (ObserverRegistry o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer rnf :: Pdu (ObserverRegistry o) r -> () # | |
data Pdu (ObserverRegistry o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (ObserverRegistry o) r where
| |
type ToPretty (ObserverRegistry o :: Type) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
data Observer o where Source #
Describes a process that observes another via Asynchronous
Pdu
messages.
An observer consists of a filter and a process id. The filter converts an observation to
a message understood by the observer process, and the ProcessId
is used to send the message.
Since: 0.16.0
Observer :: (Tangible o, IsPdu p Asynchronous, Tangible (Endpoint p), Typeable p) => (o -> Maybe (Pdu p Asynchronous)) -> Endpoint p -> Observer o |
Instances
Eq (Observer o) Source # | |
Ord (Observer o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
Show (Observer o) Source # | |
NFData o => NFData (Observer o) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
(NFData o, Show o, Typeable o, Typeable r) => IsPdu (Observer o) r Source # | A minimal Protocol for handling observations.
This is one simple way of receiving observations - of course users can use
any other Since: 0.16.0 |
Show o => Show (Pdu (Observer o) r) Source # | |
NFData o => NFData (Pdu (Observer o) r) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer | |
data Pdu (Observer o) r Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer data Pdu (Observer o) r where
| |
type ToPretty (Observer o :: Type) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer |
registerObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, TangibleObserver o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r () Source #
And an Observer
to the set of recipients for all observations reported by observed
.
Note that the observers are keyed by the observing process, i.e. a previous entry for the process
contained in the Observer
is overwritten. If you want multiple entries for a single process, just
combine several filter functions.
Since: 0.16.0
forgetObserver :: (SetMember Process (Process q) r, HasCallStack, Member Interrupts r, Typeable o, NFData o, EmbedProtocol x (ObserverRegistry o), IsPdu x Asynchronous) => Observer o -> Endpoint x -> Eff r () Source #
Send the ForgetObserver
message
Since: 0.16.0
handleObservations :: (HasCallStack, Typeable o, SetMember Process (Process q) r, NFData (Observer o)) => (o -> Eff r ()) -> Pdu (Observer o) Asynchronous -> Eff r () Source #
Based on the Pdu
instance for Observer
this simplified writing
a callback handler for observations. In order to register to
and ObserverRegistry
use toObserver
.
Since: 0.16.0
toObserver :: forall o p. (IsPdu p Asynchronous, EmbedProtocol p (Observer o), TangibleObserver o) => Endpoint p -> Observer o Source #
Use a Endpoint
as an Observer
for handleObservations
.
Since: 0.16.0
toObserverFor :: (TangibleObserver o, Typeable a, IsPdu a Asynchronous) => (o -> Pdu a Asynchronous) -> Endpoint a -> Observer o Source #
handleObserverRegistration :: forall o q r. (HasCallStack, Typeable o, SetMember Process (Process q) r, Member (ObserverState o) r, Member Logs r) => Pdu (ObserverRegistry o) Asynchronous -> Eff r () Source #
Provide the implementation for the ObserverRegistry
Protocol, this handled RegisterObserver
and ForgetObserver
messages. It also adds the ObserverState
constraint to the effect list.
Since: 0.16.0
manageObservers :: Eff (ObserverState o ': r) a -> Eff r a Source #
Keep track of registered Observer
s.
Handle the ObserverState
introduced by handleObserverRegistration
.
Since: 0.16.0
emptyObservers :: Observers o Source #
The empty ObserverState
Since: 0.24.0
observed :: forall o r q. (SetMember Process (Process q) r, Member (ObserverState o) r, Member Interrupts r, TangibleObserver o) => o -> Eff r () Source #
Report an observation to all observers.
The process needs to manageObservers
and to handleObserverRegistration
.
Since: 0.16.0
Capture Observation in a FIFO Queue
type ObservationQueueReader a = Reader (ObservationQueue a) Source #
A Reader
for an ObservationQueue
.
data ObservationQueue a Source #
Contains a TBQueue
capturing observations.
See spawnLinkObservationQueueWriter
, readObservationQueue
.
Instances
(TangibleObserver o, IsPdu (Observer o) Asynchronous, Lifted IO q, Member Logs q) => Server (ObservationQueue o) (Processes q) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Observer.Queue data StartArgument (ObservationQueue o) (Processes q) :: Type Source # type Protocol (ObservationQueue o) :: Type Source # type Model (ObservationQueue o) :: Type Source # type Settings (ObservationQueue o) :: Type Source # setup :: StartArgument (ObservationQueue o) (Processes q) -> Eff (Processes q) (Model (ObservationQueue o), Settings (ObservationQueue o)) Source # update :: StartArgument (ObservationQueue o) (Processes q) -> Event (Protocol (ObservationQueue o)) -> Eff (ModelState (ObservationQueue o) ': (SettingsReader (ObservationQueue o) ': Processes q)) () Source # | |
type Protocol (ObservationQueue o) Source # | |
type Model (ObservationQueue o) Source # | |
type Settings (ObservationQueue o) Source # | |
data StartArgument (ObservationQueue o) (Processes q) Source # | |
readObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r o Source #
Read queued observations captured and enqueued in the shared TBQueue
by spawnLinkObservationQueueWriter
.
This blocks until something was captured or an interrupt or exceptions was thrown. For a non-blocking
variant use tryReadObservationQueue
or flushObservationQueue
.
tryReadObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r (Maybe o) Source #
Read queued observations captured and enqueued in the shared TBQueue
by spawnLinkObservationQueueWriter
.
Return the oldest enqueued observation immediately or Nothing
if the queue is empty.
Use readObservationQueue
to block until an observation is observed.
flushObservationQueue :: forall o r. (Member (ObservationQueueReader o) r, HasCallStack, MonadIO (Eff r), Typeable o, Member Logs r) => Eff r [o] Source #
Read at once all currently queued observations captured and enqueued
in the shared TBQueue
by spawnLinkObservationQueueWriter
.
This returns immediately all currently enqueued observations.
For a blocking variant use readObservationQueue
.
withObservationQueue :: forall o b e len. (HasCallStack, Typeable o, Show o, Member Logs e, Lifted IO e, Integral len, Member Interrupts e) => len -> Eff (ObservationQueueReader o ': e) b -> Eff e b Source #
Create a mutable queue for observations. Use spawnLinkObservationQueueWriter
for a simple way to get
a process that enqueues all observations.
Example
withObservationQueue 100 $ do q <- ask @(ObservationQueue TestEvent) wq <- spawnLinkObservationQueueWriter q registerObserver wq testServer ... cast testServer DoSomething evt <- readObservationQueue @TestEvent ...
Since: 0.18.0
spawnLinkObservationQueueWriter :: forall o q h. (TangibleObserver o, IsPdu (Observer o) Asynchronous, Member Logs q, Lifted IO q, LogsTo h (Processes q), HasCallStack) => ObservationQueue o -> Eff (Processes q) (Observer o) Source #
Spawn a process that can be used as an Observer
that enqueues the observations into an
ObservationQueue
. See withObservationQueue
for an example.
The observations can be obtained by readObservationQueue
. All observations are captured up to
the queue size limit, such that the first message received will be first message
returned by readObservationQueue
.
Since: 0.18.0
Utilities
Logging Effect
module Control.Eff.Log
Log Writer
Asynchronous
module Control.Eff.LogWriter.Async
Console
File
module Control.Eff.LogWriter.File
UDP
module Control.Eff.LogWriter.UDP
Non-IO Log Message Capturing
Debug.Trace
Generic IO
module Control.Eff.LogWriter.IO
Unix Domain Socket
Preventing Space Leaks
module Control.Eff.Loop