@@ -86,6 +86,11 @@ defmodule ErrorTrackerDev.Live do
8686 { :noreply , assign ( socket , crash_on_render: true ) }
8787 end
8888
89+ def handle_event ( "genserver-timeout" , _params , socket ) do
90+ GenServer . call ( ErrorTrackerDev.GenServer , :timeout , 2000 )
91+ { :noreply , socket }
92+ end
93+
8994 def render ( assigns ) do
9095 if Map . has_key? ( assigns , :crash_on_render ) do
9196 raise "Crashed on render/1"
@@ -111,6 +116,9 @@ defmodule ErrorTrackerDev.Live do
111116 < li >
112117 < . link phx-click = "crash_on_handle_event " > Crash on handle_event/3</ . link >
113118 </ li >
119+ < li >
120+ < . link phx-click = "genserver-timeout " > Crash with a GenServer timeout</ . link >
121+ </ li >
114122 </ ul >
115123
116124 < h2 > Controller example</ h2 >
@@ -156,9 +164,35 @@ defmodule ErrorTrackerDev.Endpoint do
156164 plug ErrorTrackerDev.Router
157165end
158166
167+ defmodule ErrorTrackerDev.GenServer do
168+ use GenServer
169+
170+ # Client
171+
172+ def start_link ( _ ) do
173+ GenServer . start_link ( __MODULE__ , % { } )
174+ end
175+
176+ # Server (callbacks)
177+
178+ @ impl true
179+ def init ( initial_state ) do
180+ { :ok , initial_state }
181+ end
182+
183+ @ impl true
184+ def handle_call ( :timeout , _from , state ) do
185+ :timer . sleep ( 5000 )
186+ { :reply , state , state }
187+ end
188+ end
189+
159190PhoenixPlayground . start (
160191 endpoint: ErrorTrackerDev.Endpoint ,
161- child_specs: [ { ErrorTrackerDev.Repo , [ ] } ]
192+ child_specs: [
193+ { ErrorTrackerDev.Repo , [ ] } ,
194+ { ErrorTrackerDev.GenServer , [ name: ErrorTrackerDev.GenServer ] }
195+ ]
162196)
163197
164198ErrorTrackerDev.Repo . migrate ( )
0 commit comments