Search code examples
processpidelixir

Creating a fake or dummy pid in elixir


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.


Solution

  • You can use the pid/3 Erlang function directly in Elixir:

    :c.pid(0,250,0)
    

    Also - just a note from the Erlang docs:

    Converts X, Y, Z to the pid <X.Y.Z>. This function should only be used when debugging.