Skip to content

Commit 5c4b8fb

Browse files
author
José Valim
committed
Allow IEx take over while evaluating
1 parent 64296f1 commit 5c4b8fb

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/iex/lib/iex/server.ex

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ defmodule IEx.Server do
153153
# Message either go back to the main loop or exit.
154154
{ :input, ^input, code } when is_binary(code) ->
155155
evaluator <- { :eval, self, code, config }
156-
receive do
157-
{ :evaled, ^evaluator, config } ->
158-
loop(config, evaluator, evaluator_ref)
159-
end
156+
wait_eval(evaluator, evaluator_ref)
160157
{ :input, ^input, { :error, :interrupted } } ->
161158
io_error "** (EXIT) interrupted"
162159
loop(config.cache(''), evaluator, evaluator_ref)
@@ -197,6 +194,24 @@ defmodule IEx.Server do
197194
end
198195
end
199196

197+
defp wait_eval(evaluator, evaluator_ref) do
198+
receive do
199+
{ :evaled, ^evaluator, config } ->
200+
loop(config, evaluator, evaluator_ref)
201+
{ :take?, other, ref } ->
202+
other <- ref
203+
wait_eval(evaluator, evaluator_ref)
204+
{ :take, other, identifier, ref, opts } ->
205+
if allow_take?(identifier) do
206+
other <- { ref, Process.group_leader }
207+
reset_loop(opts, evaluator, evaluator_ref)
208+
else
209+
other <- { ref, nil }
210+
wait_eval(evaluator, evaluator_ref)
211+
end
212+
end
213+
end
214+
200215
defp kill_input(input) do
201216
Process.exit(input, :kill)
202217
end

0 commit comments

Comments
 (0)