# `Nebulex.Distributed.RPC`
[🔗](https://github.com/elixir-nebulex/nebulex_distributed/blob/v3.2.2/lib/nebulex/distributed/rpc.ex#L1)

RPC utilities.

# `mfa_call`

```elixir
@type mfa_call() :: {module(), atom(), [any()]}
```

Task callback

# `node_mfa_call`

```elixir
@type node_mfa_call() :: {node(), mfa_call()}
```

Group entry: node -> NFA call

# `node_mfa_map`

```elixir
@type node_mfa_map() :: %{optional(node()) =&gt; mfa_call()} | [node_mfa_call()]
```

Node group

# `reducer_acc`

```elixir
@type reducer_acc() :: any()
```

Reducer accumulator

# `reducer_fun`

```elixir
@type reducer_fun() :: (result :: any(), node_mfa_call() | node(), reducer_acc() -&gt;
                    any())
```

Reducer function spec

# `call`

```elixir
@spec call(node(), module(), atom(), [any()], timeout()) :: any()
```

Evaluates `apply(mod, fun, args)` on node `node` and returns the corresponding
evaluation result.

A timeout, in milliseconds or `:infinity`, can be given with a default value
of `5000`.

## Example

    iex> Nebulex.Distributed.RPC.call(node(), Map, :new, [[]])
    %{}

# `multi_mfa_call`

```elixir
@spec multi_mfa_call(node_mfa_map(), timeout(), reducer_acc(), reducer_fun()) :: any()
```

Similar to `multicall/7`, but it allows specifying the MFA per node.

## Example

    iex> node = node()
    iex> alias Nebulex.Distributed.RPC
    iex> RPC.multi_mfa_call(%{node => {Map, :new, [[foo: :bar]]}})
    {[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}
    iex> RPC.multi_mfa_call(%{node => {Map, :new, [[foo: :bar]]}}, 1000)
    {[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}
    iex> RPC.multi_mfa_call(
    ...>   %{node => {Map, :new, [[foo: :bar]]}},
    ...>   1000,
    ...>   {[], []}
    ...> )
    {[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}

# `multicall`

```elixir
@spec multicall(
  [node()],
  module(),
  atom(),
  [any()],
  timeout(),
  reducer_acc(),
  reducer_fun()
) :: any()
```

In contrast to a regular single-node RPC, a multicall is an RPC that is sent
concurrently from one client to multiple servers. The function evaluates
`apply(module, fun, args)` on the specified nodes and collects the answers.
Then, evaluates the `reducer_fun` function on each answer.

## Example

    iex> alias Nebulex.Distributed.RPC
    iex> RPC.multicall([node()], Map, :new, [[foo: :bar]])
    {[{:"primary@127.0.0.1", %{foo: :bar}}], []}
    iex> RPC.multicall([node()], Map, :new, [[foo: :bar]], 1000)
    {[{:"primary@127.0.0.1", %{foo: :bar}}], []}
    iex> RPC.multicall([node()], Map, :new, [[foo: :bar]], 1000, {[], []})
    {[{:"primary@127.0.0.1", %{foo: :bar}}], []}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
