Safe Haskell | None |
---|---|
Language | Haskell2010 |
A process supervisor spawns and monitors child processes.
The child processes are mapped to symbolic identifier values: Child-IDs.
This is the barest, most minimal version of a supervisor. Children can be started, but not restarted.
Children can efficiently be looked-up by an id-value, and when the supervisor is shutdown, all children will be shutdown these are actually all the features of this supervisor implementation.
Also, this minimalist supervisor only knows how to spawn a single kind of child process.
When a supervisor spawns a new child process, it expects the
child process to return a ProcessId
. The supervisor will
monitor
the child process.
This is in stark contrast to how Erlang/OTP handles things;
In the OTP Supervisor, the child has to link to the parent.
This allows the child spec to be more flexible in that no
pid
has to be passed from the child start function to the
supervisor process, and also, a child may break free from
the supervisor by unlinking.
Now while this seems nice at first, this might actually cause surprising results, since it is usually expected that stopping a supervisor also stops the children, or that a child exit shows up in the logging originating from the former supervisor.
The approach here is to allow any child to link to the supervisor to realize when the supervisor was violently killed, and otherwise give the child no chance to unlink itself from its supervisor.
This module is far simpler than the Erlang/OTP counter part,
of a simple_one_for_one
supervisor.
The future of this supervisor might not be a-lot more than it currently is. The ability to restart processes might be implemented outside of this supervisor module.
One way to do that is to implement the restart logic in a separate module, since the child-id can be reused when a child exits.
Since: 0.23.0
Synopsis
- data Sup p
- type family ChildId p
- data family StartArgument a q
- supConfigChildStopTimeout :: StartArgument (Sup p) q -> Timeout
- data SpawnErr p = AlreadyStarted (ChildId p) (Endpoint (Protocol p))
- startSupervisor :: forall p e. (HasCallStack, LogsTo IO (Processes e), Lifted IO e, TangibleSup p, Server (Sup p) e) => StartArgument (Sup p) e -> Eff (Processes e) (Endpoint (Sup p))
- stopSupervisor :: (HasCallStack, Member Interrupts e, SetMember Process (Process q0) e, Member Logs e, Lifted IO e, TangibleSup p) => Endpoint (Sup p) -> Eff e ()
- isSupervisorAlive :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, Typeable p, SetMember Process (Process q0) e) => Endpoint (Sup p) -> Eff e Bool
- monitorSupervisor :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p) => Endpoint (Sup p) -> Eff e MonitorReference
- getDiagnosticInfo :: forall p e q0. (HasCallStack, Member Interrupts e, SetMember Process (Process q0) e, TangibleSup p) => Endpoint (Sup p) -> Eff e Text
- spawnChild :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p, Typeable (Protocol p)) => Endpoint (Sup p) -> ChildId p -> Eff e (Either (SpawnErr p) (Endpoint (Protocol p)))
- lookupChild :: forall p e q0. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p, Typeable (Protocol p)) => Endpoint (Sup p) -> ChildId p -> Eff e (Maybe (Endpoint (Protocol p)))
- stopChild :: forall p e q0. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p) => Endpoint (Sup p) -> ChildId p -> Eff e Bool
Documentation
The index type of Server
supervisors.
A
manages the life cycle of the processes, running the Sup
p
methods of that specific type.Server
p
The supervisor maps an identifier value of type
to an ChildId
p
.Endpoint
p
Since: 0.24.0
Instances
data family StartArgument a q Source #
The value that defines what is required to initiate a Server
loop.
Instances
data StartArgument (ObservationQueue o) q Source # | |
data StartArgument (Sup p) q Source # | |
Defined in Control.Eff.Concurrent.Protocol.Supervisor data StartArgument (Sup p) q = MkSupConfig {
|
supConfigChildStopTimeout :: StartArgument (Sup p) q -> Timeout Source #
Runtime-Errors occurring when spawning child-processes.
Since: 0.23.0
AlreadyStarted (ChildId p) (Endpoint (Protocol p)) |
Instances
Eq (ChildId p) => Eq (SpawnErr p) Source # | |
Ord (ChildId p) => Ord (SpawnErr p) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Supervisor | |
(Typeable (Protocol p), Show (ChildId p)) => Show (SpawnErr p) Source # | |
Generic (SpawnErr p) Source # | |
NFData (ChildId p) => NFData (SpawnErr p) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Supervisor | |
type Rep (SpawnErr p) Source # | |
Defined in Control.Eff.Concurrent.Protocol.Supervisor type Rep (SpawnErr p) = D1 (MetaData "SpawnErr" "Control.Eff.Concurrent.Protocol.Supervisor" "extensible-effects-concurrent-0.25.0-IFcNAKfATcZH0zT1MWbAEU" False) (C1 (MetaCons "AlreadyStarted" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ChildId p)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Endpoint (Protocol p))))) |
startSupervisor :: forall p e. (HasCallStack, LogsTo IO (Processes e), Lifted IO e, TangibleSup p, Server (Sup p) e) => StartArgument (Sup p) e -> Eff (Processes e) (Endpoint (Sup p)) Source #
Start and link a new supervisor process with the given SpawnFun
unction.
To spawn new child processes use spawnChild
.
Since: 0.23.0
stopSupervisor :: (HasCallStack, Member Interrupts e, SetMember Process (Process q0) e, Member Logs e, Lifted IO e, TangibleSup p) => Endpoint (Sup p) -> Eff e () Source #
Stop the supervisor and shutdown all processes.
Block until the supervisor has finished.
Since: 0.23.0
isSupervisorAlive :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, Typeable p, SetMember Process (Process q0) e) => Endpoint (Sup p) -> Eff e Bool Source #
Check if a supervisor process is still alive.
Since: 0.23.0
monitorSupervisor :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p) => Endpoint (Sup p) -> Eff e MonitorReference Source #
Monitor a supervisor process.
Since: 0.23.0
getDiagnosticInfo :: forall p e q0. (HasCallStack, Member Interrupts e, SetMember Process (Process q0) e, TangibleSup p) => Endpoint (Sup p) -> Eff e Text Source #
Return a Text
describing the current state of the supervisor.
Since: 0.23.0
spawnChild :: forall p q0 e. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p, Typeable (Protocol p)) => Endpoint (Sup p) -> ChildId p -> Eff e (Either (SpawnErr p) (Endpoint (Protocol p))) Source #
Start, link and monitor a new child process using the SpawnFun
passed
to startSupervisor
.
Since: 0.23.0
lookupChild :: forall p e q0. (HasCallStack, Member Interrupts e, Member Logs e, SetMember Process (Process q0) e, TangibleSup p, Typeable (Protocol p)) => Endpoint (Sup p) -> ChildId p -> Eff e (Maybe (Endpoint (Protocol p))) Source #
Lookup the given child-id and return the output value of the SpawnFun
if the client process exists.
Since: 0.23.0