Skip to content

Commit 8d42451

Browse files
committed
Add more refdocs for HydraSdk.Extra.AppManager
1 parent 629f067 commit 8d42451

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/Internal/Extra/AppManager.purs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- | This module provides an experimental and opinionated interface
2+
-- | for managing multiple Hydra applications.
13
module HydraSdk.Internal.Extra.AppManager
24
( ActiveApp
35
, AppManager
@@ -36,27 +38,61 @@ import Effect.Aff.Class (class MonadAff, liftAff)
3638
import Effect.Class (liftEffect)
3739
import Effect.Exception (Error)
3840

41+
-- | The index of the slot within the `AppManager` that can be
42+
-- | reserved / occupied to host a Hydra application with a properly
43+
-- | configured Hydra Head.
3944
type AppManagerSlot = Int
45+
46+
-- | A secret used to authenticate application hosting requests
47+
-- | for a reserved slot.
4048
type ReservationCode = UUID
4149

50+
-- | Represents an active application within the `AppManager`, i.e.,
51+
-- | a hosted application with an established Hydra Head.
52+
-- |
53+
-- | `state`: The state of the running application. Typically a record
54+
-- | with mutable, thread-safe variables used to track the current
55+
-- | Hydra Head status, UTxO snapshot, and other relevant
56+
-- | information.
57+
-- |
58+
-- | `config`: The configuration of the running application.
59+
-- |
60+
-- | `occupiedSlot`: The number of the slot this application occupies.
4261
type ActiveApp appState appConfig =
4362
{ state :: appState
4463
, config :: appConfig
4564
, occupiedSlot :: AppManagerSlot
4665
}
4766

67+
-- | Represents a reserved slot within the `AppManager`.
68+
-- |
69+
-- | `config`: App configuration corresponding to the reserved slot.
70+
-- | This configuration is used to spin up an application instance
71+
-- | given the correct reservation code is provided.
72+
-- |
73+
-- | `reservationCode`: A secret used to authenticate hosting requests
74+
-- | for this reservation.
75+
-- |
76+
-- | `reservationMonitor`: Fiber of the assigned reservation monitor,
77+
-- | which will remove the reservation and free the slot once
78+
-- | the configured slot reservation period has expired.
4879
type ReservedSlot appConfig =
4980
{ config :: appConfig
5081
, reservationCode :: ReservationCode
5182
, reservationMonitor :: Fiber Unit
5283
}
5384

85+
-- | Hydra application manager. Tracks active application instances
86+
-- | and slots for future hosting requests.
5487
type AppManager appId appState appConfigAvailable appConfigActive =
5588
{ activeApps :: Map appId (ActiveApp appState appConfigActive)
5689
, reservedSlots :: Map AppManagerSlot (ReservedSlot appConfigAvailable)
5790
, availableSlots :: Map AppManagerSlot appConfigAvailable
5891
}
5992

93+
-- | Applies an effectful function to the `AppManager` stored in
94+
-- | an asynchronous variable (AVar) in a safe manner.
95+
-- TODO: Consider using `HydraSdk.Internal.Lib.AVar.modify` instead?
6096
withAppManager
6197
:: forall m appId appState appConfigAvailable appConfigActive a
6298
. MonadAff m

0 commit comments

Comments
 (0)