SnakeBridge.SessionContext (SnakeBridge v0.7.4)

View Source

Provides scoped session context for Python calls.

Usage

SnakeBridge.SessionContext.with_session(fn ->
  # All Python calls here use the same session
  Python.some_function()
  Python.another_function()
end)

Summary

Functions

Clears the current session context.

Creates a new session context.

Gets the current session context from the process dictionary.

Sets the current session context in the process dictionary.

Executes a function within a session context.

Types

t()

@type t() :: %SnakeBridge.SessionContext{
  created_at: integer(),
  max_refs: pos_integer(),
  owner_pid: pid(),
  session_id: String.t(),
  tags: map(),
  ttl_seconds: pos_integer()
}

Functions

clear_current()

@spec clear_current() :: t() | nil

Clears the current session context.

create(opts \\ [])

@spec create(keyword()) :: t()

Creates a new session context.

current()

@spec current() :: t() | nil

Gets the current session context from the process dictionary.

put_current(context)

@spec put_current(t()) :: t() | nil

Sets the current session context in the process dictionary.

with_session(fun)

@spec with_session((-> result)) :: result when result: term()

Executes a function within a session context.

The session is automatically registered and will be released when the owner process dies.

with_session(opts, fun)

@spec with_session(
  keyword(),
  (-> result)
) :: result
when result: term()