MingaEditor.State.Session (Minga v0.1.0)

Copy Markdown View Source

Session persistence state for the Editor.

Groups the Editor's session-related fields into a focused sub-struct: the periodic save timer and the directory paths for session files and swap files. These are set once at startup and only the timer mutates during the Editor's lifetime.

All mutations go through functions on this module.

Summary

Functions

Records a timer reference created by the session workflow.

Moves the matching native quit request to its decision prompt.

Begins one correlated native application-quit attempt.

Cancels or fails the matching native quit request and makes retry possible.

Returns a pure instruction for canceling the save timer.

Clears a completed or canceled quit request.

Completes the matching lifecycle response only after transport admission.

Latches completion of the one-time editor startup workflow.

Returns true if session persistence is enabled (session_dir is set).

Creates a new session state from startup options.

Reserves one lifecycle response before attempting nonblocking transport admission.

Accepts Discard or a clean quit and records that orderly shutdown is proceeding.

Reopens the policy workflow before retrying an undelivered Proceeding response.

Remembers the command and project root used by the last test run.

Requests quit confirmation for the editor or all editor instances.

Returns a pure instruction for restarting the save timer.

Returns keyword options for Minga.Session functions.

Accepts Save for the matching native quit request.

Returns a pure instruction for starting the periodic save timer.

Returns true if swap file recovery is enabled (swap_dir is set).

Returns keyword options for swap recovery functions.

Returns the interval used by the session workflow's periodic save timer.

Types

application_quit()

@type application_quit() ::
  :idle
  | {:requesting, application_quit_request_id()}
  | {:awaiting_decision, application_quit_request_id()}
  | {:saving, application_quit_request_id()}
  | {:responding, application_quit_request_id(),
     application_quit_policy_intent(), application_quit_response_outcome()}
  | {:proceeding, application_quit_request_id()}

application_quit_policy_intent()

@type application_quit_policy_intent() :: :inventory | :save | :discard | :cancel

application_quit_request_id()

@type application_quit_request_id() :: 0..4_294_967_295

application_quit_response_outcome()

@type application_quit_response_outcome() ::
  :needs_decision | :proceeding | :cancelled | :save_failed

last_test_command()

@type last_test_command() :: {String.t(), String.t()} | nil

pending_quit()

@type pending_quit() :: :quit | :quit_all | nil

t()

@type t() :: %MingaEditor.State.Session{
  application_quit: application_quit(),
  last_test_command: last_test_command(),
  pending_quit: pending_quit(),
  session_dir: String.t() | nil,
  session_started?: boolean(),
  swap_dir: String.t() | nil,
  timer: reference() | nil
}

Functions

accept_timer(session, ref)

@spec accept_timer(t(), reference()) :: t()

Records a timer reference created by the session workflow.

await_application_quit_decision(session, request_id)

@spec await_application_quit_decision(t(), application_quit_request_id()) ::
  {:ok, t()} | :stale

Moves the matching native quit request to its decision prompt.

begin_application_quit(session, request_id)

@spec begin_application_quit(t(), application_quit_request_id()) ::
  {:started | :duplicate | :stale, t()}

Begins one correlated native application-quit attempt.

cancel_application_quit(session, request_id)

@spec cancel_application_quit(t(), application_quit_request_id()) ::
  {:ok, t()} | :stale

Cancels or fails the matching native quit request and makes retry possible.

cancel_timer(session)

@spec cancel_timer(t()) :: {:cancel_timer, t(), reference() | nil}

Returns a pure instruction for canceling the save timer.

clear_quit_request(session)

@spec clear_quit_request(t()) :: t()

Clears a completed or canceled quit request.

complete_application_quit_response(session, request_id, outcome)

@spec complete_application_quit_response(
  t(),
  application_quit_request_id(),
  application_quit_response_outcome()
) :: {:ok, t(), application_quit_policy_intent()} | :stale

Completes the matching lifecycle response only after transport admission.

complete_startup(current, started)

@spec complete_startup(t(), t()) :: t()

Latches completion of the one-time editor startup workflow.

enabled?(session)

@spec enabled?(t()) :: boolean()

Returns true if session persistence is enabled (session_dir is set).

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new session state from startup options.

prepare_application_quit_response(session, request_id, arg3, arg4)

@spec prepare_application_quit_response(
  t(),
  application_quit_request_id(),
  application_quit_policy_intent(),
  application_quit_response_outcome()
) :: {:ok, t()} | :stale

Reserves one lifecycle response before attempting nonblocking transport admission.

proceed_application_quit(session, request_id)

@spec proceed_application_quit(t(), application_quit_request_id()) ::
  {:ok, t()} | :stale

Accepts Discard or a clean quit and records that orderly shutdown is proceeding.

reconcile_application_quit_proceeding(session, request_id)

@spec reconcile_application_quit_proceeding(t(), application_quit_request_id()) ::
  {:inventory | :save | :discard, t()} | :stale

Reopens the policy workflow before retrying an undelivered Proceeding response.

remember_test_command(session, command)

@spec remember_test_command(t(), last_test_command()) :: t()

Remembers the command and project root used by the last test run.

request_quit(session, request)

@spec request_quit(t(), :quit | :quit_all) :: t()

Requests quit confirmation for the editor or all editor instances.

restart_timer(session)

@spec restart_timer(t()) :: {:restart_timer, t(), reference() | nil}

Returns a pure instruction for restarting the save timer.

session_opts(session)

@spec session_opts(t()) :: keyword()

Returns keyword options for Minga.Session functions.

start_application_quit_save(session, request_id)

@spec start_application_quit_save(t(), application_quit_request_id()) ::
  {:ok, t()} | :stale

Accepts Save for the matching native quit request.

start_timer(session)

@spec start_timer(t()) :: {:start_timer, t()} | {:no_timer, t()}

Returns a pure instruction for starting the periodic save timer.

swap_enabled?(session)

@spec swap_enabled?(t()) :: boolean()

Returns true if swap file recovery is enabled (swap_dir is set).

swap_opts(session)

@spec swap_opts(t()) :: keyword()

Returns keyword options for swap recovery functions.

timer_interval()

@spec timer_interval() :: pos_integer()

Returns the interval used by the session workflow's periodic save timer.