diff options
author | Dan Gudmundsson <[email protected]> | 2015-01-13 12:54:21 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2015-01-13 12:54:21 +0100 |
commit | a12aa8db90712b4d176766249b5a45f3c9ab6f59 (patch) | |
tree | fa3bede8138bc793fcd85c467b7c07b4c421d154 /lib/wx/src/wxe_server.erl | |
parent | aee18f309d41691019fc323bd41c5f78be49953b (diff) | |
parent | ddbe8a821ad57bfc2a1bcd29ed80ae8cfffe1c0e (diff) | |
download | otp-a12aa8db90712b4d176766249b5a45f3c9ab6f59.tar.gz otp-a12aa8db90712b4d176766249b5a45f3c9ab6f59.tar.bz2 otp-a12aa8db90712b4d176766249b5a45f3c9ab6f59.zip |
Merge branch 'dgud/wx/connect-when-terminating/OTP-12374' into maint
* dgud/wx/connect-when-terminating/OTP-12374:
wx: Do not crash server when going down
Diffstat (limited to 'lib/wx/src/wxe_server.erl')
-rw-r--r-- | lib/wx/src/wxe_server.erl | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/wx/src/wxe_server.erl b/lib/wx/src/wxe_server.erl index 465b9da2e0..8ef568c102 100644 --- a/lib/wx/src/wxe_server.erl +++ b/lib/wx/src/wxe_server.erl @@ -223,14 +223,18 @@ handle_connect(Object, #evh{handler=undefined, cb=Callback} = EvData0, Error -> {reply, Error, State0} end; -handle_connect(Object, EvData=#evh{handler=Handler}, +handle_connect(Object, EvData=#evh{handler=Handler}, From, State0 = #state{users=Users}) -> %% Correct process is already listening just register it put(Handler, From), - User0 = #user{events=Listeners0} = gb_trees:get(From, Users), - User = User0#user{events=[{Object,EvData}|Listeners0]}, - State = State0#state{users=gb_trees:update(From, User, Users)}, - {reply, ok, State}. + case gb_trees:get(From, Users) of + {value, User0 = #user{events=Listeners0}} -> + User = User0#user{events=[{Object,EvData}|Listeners0]}, + State = State0#state{users=gb_trees:update(From, User, Users)}, + {reply, ok, State}; + none -> %% We are closing up the shop + {reply, {error, terminating}, State0} + end. invoke_cb({{Ev=#wx{}, Ref=#wx_ref{}}, FunId,_}, _S) -> %% Event callbacks |