raxx v1.0.1 Raxx.Context
Raxx.Context
is a mechanism for simple sharing of state/information between
Raxx.Middleware
s and Raxx.Server
s.
It is designed to be flexible and to enable different middlewares to operate on it without conflicts. Each separate functionality using the context can be in a different "section", containing arbitrary data.
Context is implicitly shared using the process dictionary and persists for the
duration of a single request/response cycle. If you want to pass the context
to a different process, you need to take its snapshot, pass it explicitly and
"restore" it in the other process. See Raxx.Context.get_snapshot/0
and
Raxx.Context.restore_snapshot/1
for details.
Link to this section Summary
Functions
Deletes the section from the context.
Creates a snapshot of the current process' context.
Restores a previously created context snapshot.
Retrieves the value of the context section.
Sets the value of a context section.
Link to this section Types
section_name()
section_name() :: term()
section_name() :: term()
snapshot()
(opaque)
snapshot()
snapshot()
An opaque type for the context snapshot data.
Link to this section Functions
delete(section_name)
delete(section_name()) :: term() | nil
delete(section_name()) :: term() | nil
Deletes the section from the context.
Returns the previous value of the section or nil
if one was
not set.
get_snapshot()
get_snapshot() :: snapshot()
get_snapshot() :: snapshot()
Creates a snapshot of the current process' context.
The returned context data can be passed between processes and restored
using Raxx.Context.restore_snapshot/1
restore_snapshot(context)
restore_snapshot(snapshot()) :: :ok
restore_snapshot(snapshot()) :: :ok
Restores a previously created context snapshot.
It will restore the implicit state of the context for the current
process to what it was when the snapshot was created using
Raxx.Context.get_snapshot/0
. The current context values won't
be persisted in any way.
retrieve(section_name, default \\ nil)
retrieve(section_name(), default :: term()) :: term()
retrieve(section_name(), default :: term()) :: term()
Retrieves the value of the context section.
If the section wasn't set yet, it will return nil
.
set(section_name, value)
set(section_name(), term()) :: term() | nil
set(section_name(), term()) :: term() | nil
Sets the value of a context section.
Returns the previous value of the section or nil
if one was
not set.