I am learning phoenix channels and these are my simple server and client codes
def handle_in("pomodoro1", _payload, socket) do
push(socket, "status", %{status: "start"})
:timer.sleep(5000)
push(socket, "status", %{status: "finish"})
{:reply, :ok, socket}
end
const startPomodoro = () => {
channel.push("pomodoro1")
.receive("ok", resp => console.log("received OK", resp))
.receive("error", resp => console.log("received error", resp))
.receive("timeout", resp => console.log("timeout", resp))
channel.on("status", resp => console.log(resp))
}
I getting somewhat strange response. On 1st invocation of client function I get expected response from the server
[Sun Nov 08 2020 16:22:50.923] LOG {"status": "start"}
[Sun Nov 08 2020 16:22:55.921] LOG {"status": "finish"}
[Sun Nov 08 2020 16:22:55.922] LOG received OK {}
but on 2nd invocation, I get twice the response I expect
[Sun Nov 08 2020 16:23:03.643] LOG {"status": "start"}
[Sun Nov 08 2020 16:23:03.644] LOG {"status": "start"}
[Sun Nov 08 2020 16:23:08.634] LOG {"status": "finish"}
[Sun Nov 08 2020 16:23:08.635] LOG {"status": "finish"}
[Sun Nov 08 2020 16:23:08.635] LOG received OK {}
…and so on thrice the response on 3rd invocation. Any advice?