Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Path = Path [Text]
- type ReferenceCount = Int
- type Revision = Int
- type ResourceStatusMap = Map Path (TVar (RefCounted ResourceStatus))
- data ResourceStatus
- data RefCounted a = RefCounted {
- refCount :: ReferenceCount
- refValue :: a
- type LogRunner = forall m a. MonadIO m => LoggingT m a -> m a
- data Subscriber api = Subscriber {
- subState :: !(TVar ResourceStatusMap)
- entryPoint :: !Path
- runLogging :: LogRunner
- data Event
- notify :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint Link -> URI) -> STM ()
- notifyIO :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint Link -> URI) -> IO ()
- subscribe :: Path -> Subscriber api -> STM (TVar (RefCounted ResourceStatus))
- unsubscribe :: Path -> TVar (RefCounted ResourceStatus) -> Subscriber api -> STM ()
- modifyState :: Event -> Path -> Subscriber api -> STM ()
- eventHandler :: Event -> ResourceStatus -> ResourceStatus
- doDelete :: ResourceStatus -> ResourceStatus
- doModify :: ResourceStatus -> ResourceStatus
- toSegments :: Path -> [Text]
Documentation
Instances
Eq Path Source # | |
Ord Path Source # | |
Show Path Source # | |
IsString Path Source # | |
Defined in Servant.Subscriber.Types fromString :: String -> Path # | |
Generic Path Source # | |
ToJSON Path Source # | |
Defined in Servant.Subscriber.Types | |
FromJSON Path Source # | |
type Rep Path Source # | |
Defined in Servant.Subscriber.Types |
type ReferenceCount = Int Source #
type ResourceStatusMap = Map Path (TVar (RefCounted ResourceStatus)) Source #
data ResourceStatus Source #
Instances
Eq ResourceStatus Source # | |
Defined in Servant.Subscriber.Types (==) :: ResourceStatus -> ResourceStatus -> Bool # (/=) :: ResourceStatus -> ResourceStatus -> Bool # | |
Show ResourceStatus Source # | |
Defined in Servant.Subscriber.Types showsPrec :: Int -> ResourceStatus -> ShowS # show :: ResourceStatus -> String # showList :: [ResourceStatus] -> ShowS # |
data RefCounted a Source #
RefCounted | |
|
Instances
Functor RefCounted Source # | |
Defined in Servant.Subscriber.Types fmap :: (a -> b) -> RefCounted a -> RefCounted b # (<$) :: a -> RefCounted b -> RefCounted a # |
data Subscriber api Source #
Subscriber | |
|
notify :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint Link -> URI) -> STM () Source #
Notify the subscriber about a changed resource. You have to provide a typesafe link to the changed resource. Only Symbols and Captures are allowed in this link.
You need to provide a proxy to the API too. This is needed to check that the endpoint is valid
and points to a Subscribable
resource.
One piece is still missing - we have to fill out captures, that's what the getLink parameter is for: You will typicall provide a lamda there providing needed parameters.
TODO: Example!
notifyIO :: forall api endpoint. (IsElem endpoint api, HasLink endpoint, IsValidEndpoint endpoint, IsSubscribable endpoint api) => Subscriber api -> Event -> Proxy endpoint -> (MkLink endpoint Link -> URI) -> IO () Source #
Version of notify that lives in IO
- for your convenience.
subscribe :: Path -> Subscriber api -> STM (TVar (RefCounted ResourceStatus)) Source #
Subscribe to a ResourceStatus - it will be created when not present
unsubscribe :: Path -> TVar (RefCounted ResourceStatus) -> Subscriber api -> STM () Source #
Unget a previously got ResourceState - make sure you match every call to subscribe with a call to unsubscribe!
modifyState :: Event -> Path -> Subscriber api -> STM () Source #
Modify a ResourceState if it is present in the map, otherwise do nothing.
eventHandler :: Event -> ResourceStatus -> ResourceStatus Source #
toSegments :: Path -> [Text] Source #