@@ -26,6 +26,29 @@ defmodule Migration0 do
2626 def down , do: ErrorTracker.Migration . down ( prefix: "private" )
2727end
2828
29+ defmodule ErrorTrackerDev.TimeoutGenServer do
30+ use GenServer
31+
32+ # Client
33+
34+ def start_link ( _ ) do
35+ GenServer . start_link ( __MODULE__ , % { } )
36+ end
37+
38+ # Server (callbacks)
39+
40+ @ impl true
41+ def init ( initial_state ) do
42+ { :ok , initial_state }
43+ end
44+
45+ @ impl true
46+ def handle_call ( :timeout , _from , state ) do
47+ :timer . sleep ( 5000 )
48+ { :reply , state , state }
49+ end
50+ end
51+
2952defmodule DemoLive do
3053 use Phoenix.LiveView
3154
@@ -47,6 +70,7 @@ defmodule DemoLive do
4770 < button phx-click = "inc " > +</ button >
4871 < button phx-click = "dec " > -</ button >
4972 < button phx-click = "error " > Crash on handle_event</ button >
73+ < button phx-click = "genserver-timeout " > GenServer timeout</ button >
5074
5175 < . link href = "/?crash=mount " > Crash on mount</ . link >
5276 < . link patch = "/?crash=handle_params " > Crash on handle_params</ . link >
@@ -69,6 +93,11 @@ defmodule DemoLive do
6993 raise "Crash on handle_event"
7094 end
7195
96+ def handle_event ( "genserver-timeout" , _params , socket ) do
97+ GenServer . call ( TimeoutGenServer , :timeout , 2000 )
98+ { :noreply , socket }
99+ end
100+
72101 def handle_params ( params , _uri , socket ) do
73102 if params [ "crash" ] == "handle_params" do
74103 raise "Crash on handle_params"
@@ -78,7 +107,42 @@ defmodule DemoLive do
78107 end
79108end
80109
81- PhoenixPlayground . start ( live: DemoLive , child_specs: [ ErrorTrackerDev.Repo ] )
110+ defmodule DemoRouter do
111+ use Phoenix.Router
112+ use ErrorTracker.Web , :router
113+
114+ import Phoenix.LiveView.Router
115+
116+ pipeline :browser do
117+ plug :put_root_layout , html: { PhoenixPlayground.Layout , :root }
118+ end
119+
120+ scope "/" do
121+ pipe_through :browser
122+ live "/" , DemoLive
123+ error_tracker_dashboard "/errors"
124+ end
125+ end
126+
127+ defmodule DemoEndpoint do
128+ use Phoenix.Endpoint , otp_app: :phoenix_playground
129+ plug Plug.Logger
130+ socket "/live" , Phoenix.LiveView.Socket
131+ plug Plug.Static , from: { :phoenix , "priv/static" } , at: "/assets/phoenix"
132+ plug Plug.Static , from: { :phoenix_live_view , "priv/static" } , at: "/assets/phoenix_live_view"
133+ socket "/phoenix/live_reload/socket" , Phoenix.LiveReloader.Socket
134+ plug Phoenix.LiveReloader
135+ plug Phoenix.CodeReloader , reloader: & PhoenixPlayground.CodeReloader . reload / 2
136+ plug DemoRouter
137+ end
138+
139+ PhoenixPlayground . start (
140+ endpoint: DemoEndpoint ,
141+ child_specs: [
142+ { ErrorTrackerDev.Repo , [ ] } ,
143+ { ErrorTrackerDev.TimeoutGenServer , [ name: TimeoutGenServer ] }
144+ ]
145+ )
82146
83147# Create the database if it does not exist and run migrations if needed
84148_ = Ecto.Adapters.Postgres . storage_up ( ErrorTrackerDev.Repo . config ( ) )
0 commit comments