Elixir: Resume code execution after reaching IEx.pry

烂漫一生 提交于 2019-12-12 12:24:20

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/46391388/elixir-resume-code-execution-after-reaching-iex-pry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!