When to use {:noreply, socket} vs {:reply, :ok, socket} in a Phoenix Channel?

Viewed 1204

I'm building a Javascript client app that has live communication with a Phoenix server, and wants to know if a message pushed to the server has been received. It looks like Phoenix's socket.js wants me to use something like:

channel.push("mymessage", {data: 123})
  .receive("ok", function(){ console.log("Message pushed successfully"); });

However, I can't get this event handler to fire unless I change my return value on the Phoenix app to be {:reply, :ok, socket}, like so:

  def handle_in("mymessage", %{"data" => data} = payload, socket) do
    {:reply, :ok, socket}
    # not {:noreply, socket}
  end

I guess it makes sense that {:noreply, socket} doesn't actually send a message in response to the client, but in what case would you want to send a message to the server and not have it let you know that it worked? Or am I misunderstanding something? I feel like with normal HTTP requests, you always check if the request was successful from the client.

1 Answers
Related