2424-export ([init /1 , handle_call /3 , handle_cast /2 , handle_info /2 , terminate /2 ]).
2525
2626-record (state , {
27- num_casts = 0 ,
28- num_infos = 0
27+ num_casts = 0 ,
28+ num_infos = 0
2929}).
3030
3131test () ->
@@ -88,9 +88,8 @@ test_info() ->
8888 gen_server :stop (Pid ),
8989 ok .
9090
91-
92- test_init_exception () ->
93- try
91+ test_init_exception () ->
92+ try
9493 case gen_server :start (? MODULE , throwme , []) of
9594 {ok , _Pid } ->
9695 expected_error_on_exception ;
@@ -102,7 +101,6 @@ test_info() ->
102101 {did_not_expect_an_exception , E }
103102 end .
104103
105-
106104test_late_reply () ->
107105 {ok , Pid } = gen_server :start (? MODULE , [], []),
108106 % %
@@ -134,7 +132,7 @@ test_late_reply() ->
134132test_concurrent_clients () ->
135133 {ok , Pid } = gen_server :start (? MODULE , [], []),
136134 Self = self (),
137- P1 = spawn (fun () -> make_requests (Pid , Self , 1 , 1000 ) end ),
135+ P1 = spawn (fun () -> make_requests (Pid , Self , 1 , 1000 ) end ),
138136 P2 = spawn (fun () -> make_requests (Pid , Self , 10 , 100 ) end ),
139137 P3 = spawn (fun () -> make_requests (Pid , Self , 20 , 50 ) end ),
140138 wait_for (P1 ),
@@ -174,24 +172,27 @@ handle_call(async_ping, From, State) ->
174172 erlang :spawn (gen_server , reply , [From , pong ]),
175173 {noreply , State };
176174handle_call ({reply_after , Ms , Reply }, From , State ) ->
177- spawn (fun () -> timer :sleep (Ms ), gen_server :reply (From , Reply ) end ),
175+ spawn (fun () ->
176+ timer :sleep (Ms ),
177+ gen_server :reply (From , Reply )
178+ end ),
178179 {noreply , State };
179- handle_call (get_num_casts , From , # state {num_casts = NumCasts } = State ) ->
180+ handle_call (get_num_casts , From , # state {num_casts = NumCasts } = State ) ->
180181 gen_server :reply (From , NumCasts ),
181- {noreply , State # state {num_casts = 0 }};
182- handle_call (get_num_infos , From , # state {num_infos = NumInfos } = State ) ->
182+ {noreply , State # state {num_casts = 0 }};
183+ handle_call (get_num_infos , From , # state {num_infos = NumInfos } = State ) ->
183184 gen_server :reply (From , NumInfos ),
184- {noreply , State # state {num_infos = 0 }}.
185+ {noreply , State # state {num_infos = 0 }}.
185186
186187handle_cast (crash , _State ) ->
187188 throw (test_crash );
188- handle_cast (ping , # state {num_casts = NumCasts } = State ) ->
189- {noreply , State # state {num_casts = NumCasts + 1 }};
189+ handle_cast (ping , # state {num_casts = NumCasts } = State ) ->
190+ {noreply , State # state {num_casts = NumCasts + 1 }};
190191handle_cast (_Request , State ) ->
191192 {noreply , State }.
192193
193- handle_info (ping , # state {num_infos = NumInfos } = State ) ->
194- {noreply , State # state {num_infos = NumInfos + 1 }};
194+ handle_info (ping , # state {num_infos = NumInfos } = State ) ->
195+ {noreply , State # state {num_infos = NumInfos + 1 }};
195196handle_info (_Info , State ) ->
196197 {noreply , State }.
197198
0 commit comments