In erlang it is possible to create a pid which does not correspond to a process. An example using this can be found here in Learn You Some Erlang.
pid(0,250,0).
Is there a way to do the same in elixir? The closes I have got at the moment is to create a process that immediately terminates and use that pid.
fake_pid = Process.spawn(fn -> end)
This seams like a bit of a hack, and I am unsure if there might be some slight differences between a never created pid and a dead pid.
You can use the pid/3 Erlang function directly in Elixir:
:c.pid(0,250,0)
Also - just a not from the Erlang docs:
Converts X, Y, Z to the pid . This function should only be used when debugging.
For your purposes, I would use self()
from the test code. That would resolve to the process running the current test case.
If you for some reason need to test another pid, your way of using Process.spawn/1
is quite nice, because it ensures the pid is not taken (and doesn't point to something vital in the system) and that it is already dead (or alive, if you keep it alive for the duration of the test).
The Erlang :c.pid/3
or the new Elixir 1.1 IEx.Helpers.pid/3
are only meant to be convenience functions to be used in the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With