Now we'll need to write our handlers for the cast (async) and call (sync) functions. We'll start with our cast, which inserts the data into the ETS table. handle_cast/2 is a function you need to implement for your GenServer to be able to deal with message casts, which takes in two arguments: the message you're sending (whatever data you're sending), and the current state of the GenServer, which in our case is going to store the table:
def handle_cast({:write, row}, %{table: table}=state) do :ets.insert(table, {@key, row}) {:noreply, state} end
In our write function, we sent the cast with a tuple of the message and the data we wanted to write. The message was :write, and the data was row. We also pattern ...