Error Spawning Process on Another Node

When spawning a remote process like this, does the ‘work’ (1+2 in this case) get evaluated on the local node?

Arguments (it’s just a normal list) are “evaluated” on the calling node, the function is executed on the remote node.

It’s the same as:

iex(dev@127.0.0.1)> caller = self()
iex(dev@127.0.0.1)> args = [caller, {:response, Node.self}]
#==> [#PID<0.114.0>, {:response, :"dev@127.0.0.1"}]

iex(dev@127.0.0.1)> Node.spawn(:"suv@127.0.0.1", Kernel, :send, args)
iex(dev@127.0.0.1)> flush()
#==> {:response, :"dev@127.0.0.1)"}

You can make the called function process its args and then that part would be handled by the remote node too:

iex(suv@127.0.0.1)> defmodule Worker do
                      def do_work, do: {:response, Node.self()}
                    end

iex(suv@127.0.0.1)> Worker.do_work()
#==> {:response, :"suv@127.0.0.1)"}

# -------------------- back to dev@127.0.0.1 -------------------------

iex(dev@127.0.0.1)> :erpc.call(:"suv@127.0.0.1", Worker, :do_work, [])
#==> {:response, :"suv@127.0.0.1)"}

:erpc.call here just executes the function remotely and sends back the results, similar to your Node.spawn example with send. I just wanted to mention it as it’s a pretty useful module.