@@ -231,23 +231,15 @@ defmodule Phoenix.SessionProcess do
231231 defdelegate start_session ( session_id ) , to: Phoenix.SessionProcess.ProcessSupervisor
232232
233233 @ doc """
234- Deprecated: Use `start_session/1` instead .
234+ Starts a session process with options .
235235
236- This function is kept for backward compatibility but will be removed in a future version.
237- """
238- @ deprecated "Use start_session/1 instead"
239- @ spec start ( binary ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
240- def start ( session_id ) , do: start_session ( session_id )
241-
242- @ doc """
243- Starts a session process using a custom module.
244-
245- This allows you to use a specific session process implementation instead of
246- the default configured module.
236+ This allows you to customize the module and initialization arguments.
247237
248238 ## Parameters
249239 - `session_id` - Unique binary identifier for the session
250- - `module` - Module implementing the session process behavior
240+ - `opts` - Keyword list of options:
241+ - `:module` - Module implementing the session process behavior (defaults to configured module)
242+ - `:args` - Initialization arguments passed to `init/1` (defaults to nil)
251243
252244 ## Returns
253245 - `{:ok, pid}` - Session process started successfully
@@ -257,71 +249,69 @@ defmodule Phoenix.SessionProcess do
257249
258250 ## Examples
259251
260- {:ok, pid} = Phoenix.SessionProcess.start_session("user_123", MyApp.CustomSessionProcess)
252+ # Use default module
253+ {:ok, pid} = Phoenix.SessionProcess.start_session("user_123")
254+
255+ # Use custom module
256+ {:ok, pid} = Phoenix.SessionProcess.start_session("user_123", module: MyApp.CustomSessionProcess)
261257
262- iex> result = Phoenix.SessionProcess.start_session("valid_session", Phoenix.SessionProcess.DefaultSessionProcess)
258+ # Use custom module with initialization arguments
259+ {:ok, pid} = Phoenix.SessionProcess.start_session("user_123",
260+ module: MyApp.SessionProcess,
261+ args: %{user_id: 123})
262+
263+ # Use default module with initialization arguments
264+ {:ok, pid} = Phoenix.SessionProcess.start_session("user_456", args: [debug: true])
265+
266+ iex> result = Phoenix.SessionProcess.start_session("valid_session", module: Phoenix.SessionProcess.DefaultSessionProcess)
263267 iex> match?({:ok, _pid}, result) or match?({:error, {:already_started, _pid}}, result)
264268 true
265269
266- iex> Phoenix.SessionProcess.start_session("invalid@session", Phoenix.SessionProcess.DefaultSessionProcess)
267- {:error, {:invalid_session_id, "invalid@session"}}
270+ iex> result = Phoenix.SessionProcess.start_session("valid_with_args", module: Phoenix.SessionProcess.DefaultSessionProcess, args: %{user_id: 123})
271+ iex> match?({:ok, _pid}, result) or match?({:error, {:already_started, _pid}}, result)
272+ true
268273 """
269- @ spec start_session ( binary ( ) , atom ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
270- defdelegate start_session ( session_id , module ) , to: Phoenix.SessionProcess.ProcessSupervisor
274+ @ spec start_session ( binary ( ) , keyword ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
275+ defdelegate start_session ( session_id , opts ) , to: Phoenix.SessionProcess.ProcessSupervisor
271276
272277 @ doc """
273- Deprecated: Use `start_session/2 ` instead.
278+ Deprecated: Use `start_session/1 ` instead.
274279
275280 This function is kept for backward compatibility but will be removed in a future version.
276281 """
277- @ deprecated "Use start_session/2 instead"
278- @ spec start ( binary ( ) , atom ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
279- def start ( session_id , module ) , do: start_session ( session_id , module )
282+ @ deprecated "Use start_session/1 instead"
283+ @ spec start ( binary ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
284+ def start ( session_id ) , do: start_session ( session_id )
280285
281286 @ doc """
282- Starts a session process with a custom module and initialization arguments .
287+ Deprecated: Use `start_session/2` with options instead .
283288
284- The initialization arguments are passed to the module's `init/1` callback,
285- allowing you to set up initial state or configuration.
289+ ## Migration
286290
287- ## Parameters
288- - `session_id` - Unique binary identifier for the session
289- - `module` - Module implementing the session process behavior
290- - `arg` - Initialization argument(s) passed to `init/1`
291-
292- ## Returns
293- - `{:ok, pid}` - Session process started successfully
294- - `{:error, {:already_started, pid}}` - Session already exists
295- - `{:error, {:invalid_session_id, id}}` - Invalid session ID format
296- - `{:error, {:session_limit_reached, max}}` - Maximum sessions exceeded
297-
298- ## Examples
299-
300- # With map argument
301- {:ok, pid} = Phoenix.SessionProcess.start_session("user_123", MyApp.SessionProcess, %{user_id: 123})
291+ # Old
292+ start(session_id, MyModule)
302293
303- # With keyword list
304- {:ok, pid} = Phoenix.SessionProcess.start_session("user_456", MyApp.SessionProcess, [debug: true])
305-
306- iex> result = Phoenix.SessionProcess.start_session("valid_session_with_args", Phoenix.SessionProcess.DefaultSessionProcess, %{user_id: 123})
307- iex> match?({:ok, _pid}, result) or match?({:error, {:already_started, _pid}}, result)
308- true
309-
310- iex> result = Phoenix.SessionProcess.start_session("valid_session_with_list", Phoenix.SessionProcess.DefaultSessionProcess, [debug: true])
311- iex> match?({:ok, _pid}, result) or match?({:error, {:already_started, _pid}}, result)
312- true
294+ # New
295+ start_session(session_id, module: MyModule)
313296 """
314- @ spec start_session ( binary ( ) , atom ( ) , any ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
315- defdelegate start_session ( session_id , module , arg ) , to: Phoenix.SessionProcess.ProcessSupervisor
297+ @ deprecated "Use start_session/2 with module: option instead"
298+ @ spec start ( binary ( ) , atom ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
299+ def start ( session_id , module ) , do: start_session ( session_id , module: module )
316300
317301 @ doc """
318- Deprecated: Use `start_session/3` instead.
302+ Deprecated: Use `start_session/2` with options instead.
319303
320- This function is kept for backward compatibility but will be removed in a future version.
304+ ## Migration
305+
306+ # Old
307+ start(session_id, MyModule, args)
308+
309+ # New
310+ start_session(session_id, module: MyModule, args: args)
321311 """
322- @ deprecated "Use start_session/3 instead"
312+ @ deprecated "Use start_session/2 with module: and args: options instead"
323313 @ spec start ( binary ( ) , atom ( ) , any ( ) ) :: { :ok , pid ( ) } | { :error , term ( ) }
324- def start ( session_id , module , arg ) , do: start_session ( session_id , module , arg )
314+ def start ( session_id , module , arg ) , do: start_session ( session_id , module: module , args: arg )
325315
326316 @ doc """
327317 Checks if a session process is currently running.
0 commit comments