module Proteome.Quit where

import Conc (Lock)
import Ribosome (Handler, PersistError, Rpc, RpcError, resumeReport)
import Ribosome.Effect.Persist (Persist)

import Proteome.Data.Env (Env)
import Proteome.Data.PersistBuffers (PersistBuffers)
import Proteome.PersistBuffers (StoreBuffersLock, storeBuffers)

proQuit ::
  Member (Persist PersistBuffers !! PersistError) r =>
  Members [Lock @@ StoreBuffersLock, AtomicState Env, Rpc !! RpcError, Resource, Embed IO] r =>
  Handler r ()
proQuit :: forall (r :: EffectRow).
(Member (Persist PersistBuffers !! PersistError) r,
 Members
   '[Lock @@ StoreBuffersLock, AtomicState Env, Rpc !! RpcError,
     Resource, Embed IO]
   r) =>
Handler r ()
proQuit =
  forall (eff :: (* -> *) -> * -> *) e (r :: EffectRow) a.
(Reportable e, Members '[eff !! e, Stop Report] r) =>
Sem (eff : r) a -> Sem r a
resumeReport @(Persist _) (Sem (Persist PersistBuffers : Stop Report : r) ()
 -> Sem (Stop Report : r) ())
-> Sem (Persist PersistBuffers : Stop Report : r) ()
-> Sem (Stop Report : r) ()
forall a b. (a -> b) -> a -> b
$ forall (eff :: (* -> *) -> * -> *) e (r :: EffectRow) a.
(Reportable e, Members '[eff !! e, Stop Report] r) =>
Sem (eff : r) a -> Sem r a
resumeReport @Rpc do
    Sem (Rpc : Persist PersistBuffers : Stop Report : r) ()
forall (r :: EffectRow).
(Member (Persist PersistBuffers) r,
 Members
   '[Lock @@ StoreBuffersLock, AtomicState Env, Rpc, Rpc !! RpcError,
     Resource, Embed IO]
   r) =>
Sem r ()
storeBuffers