concept cast in category elixir

This is an excerpt from Manning's book Elixir in Action.
Finally, you'll change the implementation of the key/value store to use casts. Keep in mind that a cast is a fire-and-forget type of request, so it’s not suitable for all requests. In this example, the
getrequest must be a call, because the server process needs to respond with the value associated with a given key. In contrast, theputrequest can be implemented as a cast because the client doesn’t need to wait for the response.Listing 6.8 Implementing
putas a cast (server_process_cast.ex)defmodule KeyValueStore do ... def put(pid, key, value) do ServerProcess.cast(pid, {:put, key, value}) #1 end ... def handle_cast({:put, key, value}, state) do #2 Map.put(state, key, value) end ... end #1 Issues the put request as a cast #2 Handles the put request
Listing 6.8 Implementing
putas a cast (server_process_cast.ex)defmodule KeyValueStore do ... def put(pid, key, value) do ServerProcess.cast(pid, {:put, key, value}) #1 end ... def handle_cast({:put, key, value}, state) do #2 Map.put(state, key, value) end ... end #1 Issues the put request as a cast #2 Handles the put request
Calls vs. casts
Let’s discuss some effects that calls and casts may have on your system. To refresh your memory, casts are fire-and-forget requests. A caller sends a message to the server and then immediately moves on to do something else. In contrast, a call is a blocking request, where a caller waits for the server to respond.
Remember that you’ve opted to use casts for all operations except where you need to return a response. This was a somewhat arbitrary decision, made mostly for didactic purposes. In reality, casts have a drawback: you don’t know what happened with your request. This, in turn, means you may be giving false responses to end users, as illustrated in figure 11.4.
Figure 11.4 Using casts reduces the certainty of your responses.
![]()
Because you use a cast to add a to-do entry in your system, you have no way of knowing what happened with your request. When you’re telling the end user that you succeeded, this is a guess rather than a truthful statement.

This is an excerpt from Manning's book Elixir in Action.
Finally, let’s change the implementation of the key-value store to use casts. Keep in mind that a cast is a fire-and-forget type of request, so it’s not suitable for all requests. In this example, the get request must be a call, because the server process needs to respond with the value associated with a given key. In contrast, the put request can be implemented as a cast because the client doesn’t need to wait for the response.
Let’s discuss some effects that calls and casts may have on your system. To refresh your memory, casts are fire-and-forget kinds of requests. A caller sends a message to the server and then immediately moves on to do something else. In contrast, a call is a blocking request, where a caller waits for the server to respond.
Remember that you’ve opted to use casts for all operations except where you need to return a response. This was a somewhat arbitrary decision, made mostly for didactic purposes. In reality, casts have a drawback: you don’t know what happened with your request. This in turn means you may be giving false responses to end users, as illustrated in figure 11.3.
Because you use a cast to add a to-do entry in your system, you have no way of knowing what happened with your request. So when you’re telling the end user that you succeeded, this is a guess rather than a truthful statement.