David B.
David B.

Reputation: 838

Elixir: Resume code execution after reaching IEx.pry

In ruby Ctrl - d allows to resume the execution of the code after reaching a binding.pry. What is the equivalent in Elixir for IEx.pry ?

Upvotes: 7

Views: 3442

Answers (2)

ogabriel
ogabriel

Reputation: 301

There is also the continue/0 function, which is intented for resume the execution of the current process.

Upvotes: 1

Dogbert
Dogbert

Reputation: 222388

As documented in IEx.pry/0, you can call respawn to resume the execution.

This is useful for debugging a particular chunk of code when executed by a particular process. The process becomes the evaluator of IEx commands and is temporarily changed to have a custom group leader. Those values are reverted by calling IEx.Helpers.respawn/0, which starts a new IEx shell, freeing up the pried one.

iex(1)> defmodule A do
...(1)>   require IEx
...(1)>   def a do
...(1)>     a = 1
...(1)>     b = 2
...(1)>     IEx.pry
...(1)>     IO.puts a + b
...(1)>   end
...(1)> end
{:module, A,
 <<70, 79, 82, 49, 0, 0, 12, 144, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 110,
   0, 0, 0, 12, 8, 69, 108, 105, 120, 105, 114, 46, 65, 8, 95, 95, 105, 110,
   102, 111, 95, 95, 9, 102, 117, 110, 99, ...>>, {:a, 0}}
iex(2)> A.a
Break reached: A.a/0 (iex:6)
pry(1)> a
1
pry(2)> b
2
pry(3)> respawn

Interactive Elixir (1.5.1) - press Ctrl+C to exit (type h() ENTER for help)
3
:ok

Upvotes: 13

Related Questions