timgremore commited on
Commit
8cf56d2
1 Parent(s): 643358c

chore: Credo and explain callback limitations

Browse files
lib/medical_transcription/transcription_server.ex CHANGED
@@ -10,6 +10,12 @@ defmodule MedicalTranscription.TranscriptionServer do
10
 
11
  @impl GenServer
12
  def init(init_arg) do
 
 
 
 
 
 
13
  {:ok, init_arg, {:continue, :start}}
14
  end
15
 
@@ -24,11 +30,11 @@ defmodule MedicalTranscription.TranscriptionServer do
24
  {:noreply, state}
25
  end
26
 
27
- def handle_info({:summary, result}, state) do
28
  {:noreply, state}
29
  end
30
 
31
- def handle_info(:finished, state) do
32
  {:stop, :shutdown, "Transcription finished"}
33
  end
34
 
 
10
 
11
  @impl GenServer
12
  def init(init_arg) do
13
+ # NOTE: The rule is: don't do anything slow or risky in your GenServer's init function.
14
+ # But that isn't always practical. GenServers have a reasonably elegant solution to this: handle_continue/2.
15
+ # We can change our init function to return {:ok, INTIAL_STATE, {:continue, CONTINUE_TYPE}} which will both
16
+ # unblock the initialization and guarantee that handle_continue/2 is called before any other message is processed.
17
+ #
18
+ # Explanation from: https://www.openmymind.net/Elixir-A-Little-Beyond-The-Basics-Part-8-genservers
19
  {:ok, init_arg, {:continue, :start}}
20
  end
21
 
 
30
  {:noreply, state}
31
  end
32
 
33
+ def handle_info({:summary, _result}, state) do
34
  {:noreply, state}
35
  end
36
 
37
+ def handle_info(:finished, _state) do
38
  {:stop, :shutdown, "Transcription finished"}
39
  end
40