raxx v0.17.6 Raxx.Context

Raxx.Context is a mechanism for simple sharing of state/information between Raxx.Middlewares and Raxx.Servers.

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

Types

An opaque type for the context snapshot data

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

Link to this type section_name()
section_name() :: term()
Link to this opaque snapshot() (opaque)

An opaque type for the context snapshot data.

Link to this section Functions

Link to this function delete(section_name)
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.

Link to this function get_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

Link to this function restore_snapshot(context)
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.

Link to this function retrieve(section_name, default \\ nil)
retrieve(section_name(), default :: term()) :: term()

Retrieves the value of the context section.

If the section wasn’t set yet, it will return nil.

Link to this function set(section_name, value)
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.