Skip to content

Commit 01bfef0

Browse files
committed
feat: add start_link/1 and child_spec/1 delegations to Phoenix.SessionProcess
Add start_link/1 and child_spec/1 functions that delegate to Phoenix.SessionProcess.Supervisor, allowing users to use the cleaner syntax {Phoenix.SessionProcess, []} in their supervision tree instead of {Phoenix.SessionProcess.Supervisor, []}. Changes: - Added defdelegate start_link/1 to Phoenix.SessionProcess.Supervisor - Added defdelegate child_spec/1 to Phoenix.SessionProcess.Supervisor - Updated documentation in Phoenix.SessionProcess module docstring - Updated README.md Quick Start example - Updated CLAUDE.md configuration example This provides a cleaner, more intuitive API for users while maintaining backward compatibility with the explicit Supervisor module usage. Example: # New cleaner syntax {Phoenix.SessionProcess, []} # Still works {Phoenix.SessionProcess.Supervisor, []}
1 parent 793caf0 commit 01bfef0

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ config :phoenix_session_process,
411411
# lib/my_app/application.ex
412412
def start(_type, _args) do
413413
children = [
414-
Phoenix.SessionProcess.Supervisor,
414+
{Phoenix.SessionProcess, []},
415+
# Or: Phoenix.SessionProcess.Supervisor,
415416
# ... other children
416417
]
417418

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Add the supervisor to your application's supervision tree:
5959
def start(_type, _args) do
6060
children = [
6161
# ... other children ...
62-
{Phoenix.SessionProcess.Supervisor, []}
62+
{Phoenix.SessionProcess, []}
63+
# Or use: {Phoenix.SessionProcess.Supervisor, []}
6364
]
6465

6566
Supervisor.start_link(children, strategy: :one_for_one)

lib/phoenix/session_process.ex

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ defmodule Phoenix.SessionProcess do
2424
def start(_type, _args) do
2525
children = [
2626
# ... other children ...
27-
{Phoenix.SessionProcess.Supervisor, []}
27+
{Phoenix.SessionProcess, []}
28+
# Or use: {Phoenix.SessionProcess.Supervisor, []}
2829
]
2930
3031
Supervisor.start_link(children, strategy: :one_for_one)
@@ -151,6 +152,61 @@ defmodule Phoenix.SessionProcess do
151152
alias Phoenix.SessionProcess.{Cleanup, Config, ProcessSupervisor}
152153
alias Phoenix.SessionProcess.Registry, as: SessionRegistry
153154

155+
@doc """
156+
Starts the SessionProcess supervision tree.
157+
158+
This function delegates to `Phoenix.SessionProcess.Supervisor.start_link/1` and
159+
should be used in your application's supervision tree for cleaner syntax.
160+
161+
## Parameters
162+
- `init_arg` - Initialization argument (typically an empty list `[]`)
163+
164+
## Returns
165+
- `{:ok, pid}` - Supervisor started successfully
166+
- `{:error, reason}` - If supervisor failed to start
167+
168+
## Examples
169+
170+
In your application supervision tree:
171+
172+
def start(_type, _args) do
173+
children = [
174+
# Cleaner syntax using Phoenix.SessionProcess
175+
{Phoenix.SessionProcess, []}
176+
177+
# Or explicitly use the Supervisor module
178+
{Phoenix.SessionProcess.Supervisor, []}
179+
]
180+
181+
Supervisor.start_link(children, strategy: :one_for_one)
182+
end
183+
"""
184+
@spec start_link(any()) :: Supervisor.on_start()
185+
defdelegate start_link(init_arg), to: Phoenix.SessionProcess.Supervisor
186+
187+
@doc """
188+
Returns a child specification for starting the SessionProcess supervision tree.
189+
190+
This is automatically called when adding `{Phoenix.SessionProcess, []}` to a
191+
supervision tree. The function delegates to `Phoenix.SessionProcess.Supervisor.child_spec/1`.
192+
193+
## Parameters
194+
- `init_arg` - Initialization argument passed to `start_link/1`
195+
196+
## Returns
197+
- Child specification map with `:id`, `:start`, and other supervisor options
198+
199+
## Examples
200+
201+
The child spec is automatically used in supervision trees:
202+
203+
children = [
204+
{Phoenix.SessionProcess, []} # child_spec/1 is called automatically
205+
]
206+
"""
207+
@spec child_spec(any()) :: Supervisor.child_spec()
208+
defdelegate child_spec(init_arg), to: Phoenix.SessionProcess.Supervisor
209+
154210
@doc """
155211
Starts a session process using the default configured module.
156212

0 commit comments

Comments
 (0)