Example

  1. module Demo.Sup (start) where
  2. import Prelude
  3. import Demo.Event as Event
  4. import Demo.Server as Server
  5. import Demo.FSM.PushButton as FSM
  6. import Control.Behaviour.Supervisor
  7. ( Init
  8. , initOk
  9. , Strategy(..)
  10. , childSpec
  11. , startSupWith
  12. )
  13. name :: Atom
  14. name = :sup
  15. start :: Process Pid
  16. start = startSupWith name init
  17. init :: Init
  18. init = initOk (OneForOne, 10, 100)
  19. [ childSpec "Demo.Event" Event.start
  20. , childSpec "Demo.Server" Server.start
  21. , childSpec "Demo.Statem" FSM.start
  22. ]

Start a Supervisor process

  1. -- Start a supervisor process.
  2. startSup :: Init -> Process Pid
  3. -- Start a supervisor with name.
  4. startSupWith :: Name -> Init -> Process Pid

Init callback

  1. type SupFlags = (Strategy, Intensity, Integer)
  2. -- | Init Result
  3. data InitResult
  4. = InitOk SupFlags [ChildSpec]
  5. -- ^ {ok, State}
  6. | InitIgnore
  7. -- ^ ignore
  8. -- | Init callback
  9. type Init = Process InitResult

Restart Strategy

See: Erlang Restart Strategy

  1. data Strategy
  2. = OneForAll
  3. -- ^ Restart all child processes if one terminated.
  4. | OneForOne
  5. -- ^ Restart only the child processs terminated.
  6. | RestForOne
  7. -- ^ TODO: comment...
  8. | SimpleOneForOne
  9. -- ^ TODO: comment...

OneForOne

OneForAll

OneForRest

SimpleOneForOne