Skip to content

Commit f997af2

Browse files
GenServer: Rename continue argument in handle_continue/2 (#11793)
As I was reading the docs, it was not clear what the `continue` argument was just by reading its name.
1 parent 4d6c433 commit f997af2

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lib/elixir/lib/gen_server.ex

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ defmodule GenServer do
434434
except the process is hibernated before entering the loop. See
435435
`c:handle_call/3` for more information on hibernation.
436436
437-
Returning `{:ok, state, {:continue, continue}}` is similar to
437+
Returning `{:ok, state, {:continue, continue_arg}}` is similar to
438438
`{:ok, state}` except that immediately after entering the loop,
439-
the `c:handle_continue/2` callback will be invoked with the value
440-
`continue` as first argument.
439+
the `c:handle_continue/2` callback will be invoked with `continue_arg`
440+
as the first argument and `state` as the second one.
441441
442442
Returning `:ignore` will cause `start_link/3` to return `:ignore` and
443443
the process will exit normally without entering the loop or calling
@@ -460,7 +460,7 @@ defmodule GenServer do
460460
"""
461461
@callback init(init_arg :: term) ::
462462
{:ok, state}
463-
| {:ok, state, timeout | :hibernate | {:continue, term}}
463+
| {:ok, state, timeout | :hibernate | {:continue, continue_arg :: term}}
464464
| :ignore
465465
| {:stop, reason :: any}
466466
when state: any
@@ -487,9 +487,10 @@ defmodule GenServer do
487487
`GenServer` causes garbage collection and leaves a continuous heap that
488488
minimises the memory used by the process.
489489
490-
Returning `{:reply, reply, new_state, {:continue, continue}}` is similar to
491-
`{:reply, reply, new_state}` except `c:handle_continue/2` will be invoked
492-
immediately after with the value `continue` as first argument.
490+
Returning `{:reply, reply, new_state, {:continue, continue_arg}}` is similar to
491+
`{:reply, reply, new_state}` except that `c:handle_continue/2` will be invoked
492+
immediately after with `continue_arg` as the first argument and
493+
`state` as the second one.
493494
494495
Hibernating should not be used aggressively as too much time could be spent
495496
garbage collecting. Normally it should only be used when a message is not
@@ -512,7 +513,7 @@ defmodule GenServer do
512513
process exits without replying as the caller will be blocking awaiting a
513514
reply.
514515
515-
Returning `{:noreply, new_state, timeout | :hibernate | {:continue, continue}}`
516+
Returning `{:noreply, new_state, timeout | :hibernate | {:continue, continue_arg}}`
516517
is similar to `{:noreply, new_state}` except a timeout, hibernation or continue
517518
occurs as with a `:reply` tuple.
518519
@@ -528,9 +529,10 @@ defmodule GenServer do
528529
"""
529530
@callback handle_call(request :: term, from, state :: term) ::
530531
{:reply, reply, new_state}
531-
| {:reply, reply, new_state, timeout | :hibernate | {:continue, term}}
532+
| {:reply, reply, new_state,
533+
timeout | :hibernate | {:continue, continue_arg :: term}}
532534
| {:noreply, new_state}
533-
| {:noreply, new_state, timeout | :hibernate | {:continue, term}}
535+
| {:noreply, new_state, timeout | :hibernate | {:continue, continue_arg :: term}}
534536
| {:stop, reason, reply, new_state}
535537
| {:stop, reason, new_state}
536538
when reply: term, new_state: term, reason: term
@@ -551,9 +553,10 @@ defmodule GenServer do
551553
`{:noreply, new_state}` except the process is hibernated before continuing the
552554
loop. See `c:handle_call/3` for more information.
553555
554-
Returning `{:noreply, new_state, {:continue, continue}}` is similar to
556+
Returning `{:noreply, new_state, {:continue, continue_arg}}` is similar to
555557
`{:noreply, new_state}` except `c:handle_continue/2` will be invoked
556-
immediately after with the value `continue` as first argument.
558+
immediately after with `continue_arg` as the first argument and
559+
`state` as the second one.
557560
558561
Returning `{:stop, reason, new_state}` stops the loop and `c:terminate/2` is
559562
called with the reason `reason` and state `new_state`. The process exits with
@@ -564,7 +567,7 @@ defmodule GenServer do
564567
"""
565568
@callback handle_cast(request :: term, state :: term) ::
566569
{:noreply, new_state}
567-
| {:noreply, new_state, timeout | :hibernate | {:continue, term}}
570+
| {:noreply, new_state, timeout | :hibernate | {:continue, continue_arg :: term}}
568571
| {:stop, reason :: term, new_state}
569572
when new_state: term
570573

@@ -581,12 +584,12 @@ defmodule GenServer do
581584
"""
582585
@callback handle_info(msg :: :timeout | term, state :: term) ::
583586
{:noreply, new_state}
584-
| {:noreply, new_state, timeout | :hibernate | {:continue, term}}
587+
| {:noreply, new_state, timeout | :hibernate | {:continue, continue_arg :: term}}
585588
| {:stop, reason :: term, new_state}
586589
when new_state: term
587590

588591
@doc """
589-
Invoked to handle `continue` instructions.
592+
Invoked to handle continue instructions.
590593
591594
It is useful for performing work after initialization or for splitting the work
592595
in a callback in multiple steps, updating the process state along the way.
@@ -596,11 +599,11 @@ defmodule GenServer do
596599
This callback is optional. If one is not implemented, the server will fail
597600
if a continue instruction is used.
598601
"""
599-
@callback handle_continue(continue :: term, state :: term) ::
602+
@callback handle_continue(continue_arg, state :: term) ::
600603
{:noreply, new_state}
601-
| {:noreply, new_state, timeout | :hibernate | {:continue, term}}
604+
| {:noreply, new_state, timeout | :hibernate | {:continue, continue_arg}}
602605
| {:stop, reason :: term, new_state}
603-
when new_state: term
606+
when new_state: term, continue_arg: term
604607

605608
@doc """
606609
Invoked when the server is about to exit. It should do any cleanup required.

0 commit comments

Comments
 (0)