ping and monitoring bus actor not service
This commit is contained in:
parent
c98e8718a8
commit
9da6231702
1 changed files with 14 additions and 3 deletions
|
@ -12,6 +12,7 @@ init(R, _) ->
|
|||
|
||||
websocket_init(S) ->
|
||||
Ref = st:lookup(wsbus),
|
||||
erlang:send_after(?TTL_PING, self(), ping),
|
||||
{ok, S#{wsbus => nil, ref_wsbus => Ref}}.
|
||||
|
||||
websocket_handle({text, <<Data/binary>>}, S) ->
|
||||
|
@ -42,10 +43,20 @@ websocket_info({send, List}, S) when is_list(List) ->
|
|||
{List, S};
|
||||
websocket_info({'DOWN', _, process, PID, _}, #{wsbus := PID} = S) ->
|
||||
{ok, S#{wsbus => nil, ref_wsbus => st:lookup(wsbus)}};
|
||||
websocket_info({_, {send, _} = Msg}, S) ->
|
||||
websocket_info(Msg, S);
|
||||
websocket_info({_, {Ref, {error, notfound}}}, #{ref_wsbus := Ref} = S) ->
|
||||
{ok, S#{ref_wsbus => st:lookup(wsbus)}};
|
||||
websocket_info({_, {Ref, {ok, PID}}}, #{ref_wsbus := Ref} = S) ->
|
||||
erlang:monitor(process, PID),
|
||||
{ok, maps:remove(ref_wsbus, S#{wsbus => PID})};
|
||||
websocket_info({_, {Ref, {ok, Service}}}, #{wsbus := nil, ref_wsbus := Ref} = S) ->
|
||||
try gen_server:call(Service, {new, self()}) of
|
||||
{ok, PID} ->
|
||||
erlang:monitor(process, PID),
|
||||
{ok, maps:remove(ref_wsbus, S#{wsbus => PID})};
|
||||
{error, ignored} ->
|
||||
{ok, S#{ref_wsbus => st:lookup(wsbus)}}
|
||||
catch
|
||||
_:_ ->
|
||||
{ok, S#{ref_wsbus => st:lookup(wsbus)}}
|
||||
end;
|
||||
websocket_info(_, S) ->
|
||||
{ok, S}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue