mirror of
https://github.com/zap-proto/haskell.git
synced 2026-10-30 15:05:00 +00:00
18 lines
678 B
Haskell
18 lines
678 B
Haskell
{-# LANGUAGE RankNTypes #-}
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
module Internal.Rpc.Export (export) where
|
|
|
|
import Zap.Rpc.Common (Client (..))
|
|
import Zap.Rpc.Server
|
|
import qualified Zap.Rpc.Untyped as URpc
|
|
import Control.Monad.STM.Class (MonadSTM (liftSTM))
|
|
import Data.Proxy (Proxy (..))
|
|
import Supervisors (Supervisor)
|
|
|
|
-- | Export the server as a client for interface @i@. Spawns a server thread
|
|
-- with its lifetime bound to the supervisor.
|
|
export :: forall i s m. (MonadSTM m, Export i, Server i s, SomeServer s) => Supervisor -> s -> m (Client i)
|
|
export sup srv = liftSTM $ Client <$> URpc.export sup (exportToServerOps (Proxy @i) srv)
|