Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype LifecycleT m a = MkLifecycleT {
- unLifecycleT :: MVar LifeState -> m a
- type Lifecycle = LifecycleT IO
- runLifecycle :: forall m. (MonadException m, MonadTunnelIO m) => LifecycleT m --> m
- lifecycleOnCloseIO :: MonadIO m => IO () -> LifecycleT m ()
- lifecycleOnClose :: MonadAskUnliftIO m => m () -> LifecycleT m ()
- lifecycleGetCloser :: forall m a. MonadIO m => LifecycleT m a -> LifecycleT m (a, IO ())
- forkLifecycle :: MonadUnliftIO m => m () -> LifecycleT m ThreadId
- lifecycleMonitor :: MonadIO m => LifecycleT m (IO Bool)
- type With (m :: k -> Type) (t :: Type) = forall (r :: k). (t -> m r) -> m r
- withLifecycle :: forall m a. (MonadException m, MonadTunnelIO m) => LifecycleT m a -> With m a
- lifecycleWith :: (MonadCoroutine m, MonadAskUnliftIO m) => With m t -> LifecycleT m t
- data LifeState
- pattern NoLifeState :: LifeState
- lifeStateModify :: (IO --> IO) -> LifeState -> LifeState
- closeLifeState :: LifeState -> IO ()
- getLifeState :: forall m a. MonadIO m => LifecycleT m a -> m (a, LifeState)
- addLifeState :: MonadIO m => LifeState -> LifecycleT m ()
- modifyLifeState :: forall m. MonadIO m => (LifeState -> LifeState) -> LifecycleT m --> LifecycleT m
Documentation
newtype LifecycleT m a Source #
This is for managing the automatic closing of opened resources.
MkLifecycleT | |
|
Instances
type Lifecycle = LifecycleT IO Source #
This is the expected most common use.
runLifecycle :: forall m. (MonadException m, MonadTunnelIO m) => LifecycleT m --> m Source #
Run the lifecycle, then close all resources in reverse order they were opened.
lifecycleOnCloseIO :: MonadIO m => IO () -> LifecycleT m () Source #
Add a closing action.
lifecycleOnClose :: MonadAskUnliftIO m => m () -> LifecycleT m () Source #
Add a closing action.
lifecycleGetCloser :: forall m a. MonadIO m => LifecycleT m a -> LifecycleT m (a, IO ()) Source #
Runs the given lifecycle, returning a closer. This is how you close things out of order.
The closer is an idempotent action that will close the lifecycle only if it hasn't already been closed. The closer will also be run as the closer of the resulting lifecycle.
forkLifecycle :: MonadUnliftIO m => m () -> LifecycleT m ThreadId Source #
Fork a thread that will complete in this lifecycle. Closing will wait for the thread to finish.
lifecycleMonitor :: MonadIO m => LifecycleT m (IO Bool) Source #
With
type With (m :: k -> Type) (t :: Type) = forall (r :: k). (t -> m r) -> m r Source #
A type synoynm for a common pattern for closing opened resources, e.g.
withFile
,
withBinaryFile
,
etc.
withLifecycle :: forall m a. (MonadException m, MonadTunnelIO m) => LifecycleT m a -> With m a Source #
Convert a lifecycle to a function that uses the "with" pattern.
lifecycleWith :: (MonadCoroutine m, MonadAskUnliftIO m) => With m t -> LifecycleT m t Source #
Convert a function that uses the "with" pattern to a lifecycle.
LifeState
This represents all the actions that need to be done when closing the lifecycle.
pattern NoLifeState :: LifeState Source #
closeLifeState :: LifeState -> IO () Source #
getLifeState :: forall m a. MonadIO m => LifecycleT m a -> m (a, LifeState) Source #
Runs a lifecycle, but instead of running the closing actions, return them as a LifeState
.
addLifeState :: MonadIO m => LifeState -> LifecycleT m () Source #
modifyLifeState :: forall m. MonadIO m => (LifeState -> LifeState) -> LifecycleT m --> LifecycleT m Source #