Here’s a module that defines a function we’d like to run as a separate process.
|||defmodule SpawnBasic do|
|||def greet do|
Yup, that’s it. There’s nothing special—it’s just regular code.
Let’s fire up iex and play:
First let’s call it as a regular function:
Now let’s run it in a separate process:
|||iex> spawn(SpawnBasic, :greet, )|
The spawn function kicks off a new process. It comes in many forms, but the two simplest ones let you run an anonymous function and run a named function in a module, passing a list of arguments. (We used the latter here.)
The spawn ...