Skip to content

Commit 920c680

Browse files
committed
Handle case when restoring process without saved variables
1 parent 4fe0320 commit 920c680

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/chorex/runtime.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ defmodule Chorex.Runtime do
5656
# knock off the recover frame
5757
|> Enum.drop(1)
5858

59+
# Restore vars if given; see note in RuntimeMonitor.recover
60+
vars = if is_map(vars), do: vars, else: state.vars
61+
5962
state = %{state | config: new_network, stack: new_stack, vars: vars}
6063

6164
continue_on_stack(nil, state)

lib/chorex/runtime_monitor.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,14 @@ defmodule Chorex.RuntimeMonitor do
297297
Called for effect; no meaningful return value.
298298
"""
299299
def recover(name, pid, new_config, barrier_token, state) do
300-
{_, recover_state} = assoc_get(state.state_store[name], barrier_token)
301-
send(pid, {:recover, state.session_token, new_config, barrier_token, recover_state.vars})
300+
case assoc_get(state.state_store[name], barrier_token) do
301+
{_, recover_state} ->
302+
send(pid, {:recover, state.session_token, new_config, barrier_token, recover_state.vars})
303+
304+
nil ->
305+
# Sometimes no state has been saved yet; in this case, don't bother restoring variables
306+
send(pid, {:recover, state.session_token, new_config, barrier_token, nil})
307+
end
302308
:ok
303309
end
304310

lib/utils.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ defmodule Utils do
4949
# _ -> true
5050
# end)
5151

52+
# Lispy: treat nil like []
53+
def assoc_get(nil, _), do: nil
5254
def assoc_get(alist, k),
5355
do:
5456
Enum.find(alist, fn

0 commit comments

Comments
 (0)