Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Store ctx = Store {}
- data State ctx = State {}
- withStore :: PropagationStrategy -> Maybe ctx -> (Store ctx -> IO a) -> IO a
- newStore :: PropagationStrategy -> Maybe ctx -> IO (Store ctx)
- use :: Store ctx -> ctx -> IO a -> IO a
- push :: Store ctx -> ctx -> IO ()
- pop :: Store ctx -> IO ()
- mineMay :: Store ctx -> IO (Maybe ctx)
- mineMayOnDefault :: (Maybe ctx -> Maybe ctx) -> Store ctx -> IO (Maybe ctx)
- setDefault :: Store ctx -> ctx -> IO ()
- 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
:: 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 -> IO a) | |
-> IO 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.
'Context.withNonEmptyStore'/'Context.withEmptyStore' should generally be preferred over this
function when acquiring a Store
.
Since: 0.1.0.0
:: 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 |
-> IO (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 :: Store ctx -> ctx -> IO a -> IO 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 :: Store ctx -> IO (Maybe ctx) Source #
Provide the calling thread its current context from the specified
Store
, if present.
Since: 0.1.0.0
setDefault :: Store ctx -> ctx -> IO () 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
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 #