Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Store ctx = Store {}
- data State ctx = State {}
- data NotFoundException = NotFoundException {}
- withStore :: forall m ctx a. (MonadIO m, MonadMask m) => PropagationStrategy -> Maybe ctx -> (Store ctx -> m a) -> m a
- newStore :: forall m ctx. MonadIO m => PropagationStrategy -> Maybe ctx -> m (Store ctx)
- use :: forall m ctx a. (MonadIO m, MonadMask m) => Store ctx -> ctx -> m a -> m a
- push :: Store ctx -> ctx -> IO ()
- pop :: Store ctx -> IO ()
- mineMay :: forall m ctx. MonadIO m => Store ctx -> m (Maybe ctx)
- mineMayOnDefault :: forall m ctx. MonadIO m => (Maybe ctx -> Maybe ctx) -> Store ctx -> m (Maybe ctx)
- setDefault :: forall m ctx. MonadIO m => Store ctx -> ctx -> m ()
- throwContextNotFound :: forall m a. (MonadIO m, MonadThrow m) => m a
- data View ctx where
- view :: (MonadIO m, MonadThrow m) => View ctx -> m ctx
- viewMay :: MonadIO m => View ctx -> m (Maybe ctx)
- toView :: Store ctx -> View ctx
- data PropagationStrategy
- newtype Registry = Registry {}
- data AnyStore where
- MkAnyStore :: forall ctx. Store ctx -> AnyStore
- registry :: Registry
- emptyRegistry :: IO Registry
- withPropagator :: ((IO a -> IO a) -> IO b) -> IO b
- withRegisteredPropagator :: Registry -> ((IO a -> IO a) -> IO b) -> IO b
- register :: Registry -> Store ctx -> IO ()
- unregister :: Registry -> Store ctx -> IO ()
- bug :: HasCallStack => String -> a
Disclaimer
In general, changes to this module will not be reflected in the library's version updates. Direct use of this module should be done with extreme care as it becomes very easy to violate the library's invariants.
Store-related
Opaque type that manages thread-indexed storage of context values.
Since: 0.1.0.0
data NotFoundException Source #
An exception which may be thrown when the calling thread does not have a registered context.
Since: 0.1.0.0
Instances
Exception NotFoundException Source # | |
Defined in Context.Internal | |
Generic NotFoundException Source # | |
Defined in Context.Internal type Rep NotFoundException :: Type -> Type # from :: NotFoundException -> Rep NotFoundException x # to :: Rep NotFoundException x -> NotFoundException # | |
Show NotFoundException Source # | |
Defined in Context.Internal showsPrec :: Int -> NotFoundException -> ShowS # show :: NotFoundException -> String # showList :: [NotFoundException] -> ShowS # | |
Eq NotFoundException Source # | |
Defined in Context.Internal (==) :: NotFoundException -> NotFoundException -> Bool # (/=) :: NotFoundException -> NotFoundException -> Bool # | |
type Rep NotFoundException Source # | |
Defined in Context.Internal type Rep NotFoundException = D1 ('MetaData "NotFoundException" "Context.Internal" "context-0.2.0.1-DiLV6VUVy9GGncT6FdoMXM" 'False) (C1 ('MetaCons "NotFoundException" 'PrefixI 'True) (S1 ('MetaSel ('Just "threadId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ThreadId))) |
:: forall m ctx a. (MonadIO m, MonadMask m) | |
=> PropagationStrategy | The strategy used by Context.Concurrent for propagating context from a "parent" thread to a new thread. |
-> Maybe ctx | The default value for the Providing a value will produce a non-empty Providing |
-> (Store ctx -> m a) | |
-> m a |
Provides a new Store
. This is a lower-level function and is provided
mainly to give library authors more fine-grained control when using a Store
as an implementation detail.
withNonEmptyStore
/withEmptyStore
should generally be preferred over this
function when acquiring a Store
.
Since: 0.1.0.0
:: forall m ctx. MonadIO m | |
=> PropagationStrategy | The strategy used by Context.Concurrent for propagating context from a "parent" thread to a new thread. |
-> Maybe ctx | The default value for the Providing a value will produce a non-empty Providing |
-> m (Store ctx) |
Creates a new Store
. This is a lower-level function and is provided
only to support the use case of creating a Store
as a global:
store :: Store Int store = unsafePerformIO $ Context.newStore Context.defaultPropagation Nothing {-# NOINLINE store #-}
Outside of the global variable use case, withNonEmptyStore
,
withEmptyStore
, or even the lower-level
withStore
should always be preferred over this function
when acquiring a Store
.
Since: 0.1.0.0
use :: forall m ctx a. (MonadIO m, MonadMask m) => Store ctx -> ctx -> m a -> m a Source #
Register a context in the specified Store
on behalf of the calling
thread, for the duration of the specified action.
Since: 0.1.0.0
mineMay :: forall m ctx. MonadIO m => Store ctx -> m (Maybe ctx) Source #
Provide the calling thread its current context from the specified
Store
, if present.
Since: 0.1.0.0
mineMayOnDefault :: forall m ctx. MonadIO m => (Maybe ctx -> Maybe ctx) -> Store ctx -> m (Maybe ctx) Source #
setDefault :: forall m ctx. MonadIO m => Store ctx -> ctx -> m () Source #
Set the default context value for a store. If the store was initialized as an empty store, this function converts it to a non-empty store. If the store was initialized as a non-empty store, this overwrites the default context value.
One common use case for this function is to convert an empty store in a global variable to a non-empty store while the application is initializing/acquiring resources:
depsStore :: Store Dependencies depsStore = unsafePerformIO $ Context.newStore Context.defaultPropagation Nothing {-# NOINLINE depsStore #-} main :: IO () main = do let config = -- ... withDependencies config \deps -> do Context.setDefault depsStore deps -- ...
Since: 0.1.0.0
throwContextNotFound :: forall m a. (MonadIO m, MonadThrow m) => m a Source #
View-related
view :: (MonadIO m, MonadThrow m) => View ctx -> m ctx Source #
Provide the calling thread a view of its current context from the specified
View
. Throws a NotFoundException
when the calling
thread has no registered context.
Since: 0.1.1.0
viewMay :: MonadIO m => View ctx -> m (Maybe ctx) Source #
Provide the calling thread a view of its current context from the specified
View
, if present.
Since: 0.1.1.0
Propagation-related
data PropagationStrategy Source #
The PropagationStrategy
controls the behavior used by
Context.Concurrent when propagating context from a "parent" thread to a new
thread.
Since: 0.1.0.0
Miscellaneous
bug :: HasCallStack => String -> a Source #