What is the simplest way to create a first-in, first-out queue to handle binary data that will be consumed from an external process?

what happens is that i am receiving binary data in my (speech recognition) application, but after some time, heap overflow occurs. I thought my memory wasn’t being freed, but that wasn’t the problem… what I think is happening is that recognizer_partial_result and recognizer_final_result overlap causing the error
This is where I manage the application inside a channel:

def handle_in("file_chunk", {:binary, <<samples :: binary>>}, socket) do
    recognizer = GenServer.call(Model, :get_recognizer)
    wave = :vosk.recognizer_accept_waveform(recognizer, samples)
    if  wave == 0 do
      partial = :vosk.recognizer_partial_result(recognizer)
      IO.inspect(wave, label: "------wave------")

      IO.inspect(partial, label: "-------texto--------")
      # :timer.sleep(10)

       {:noreply,  socket}
    else if wave == 1 do
      result = :vosk.recognizer_final_result(recognizer)
      # :vosk.recognizer_reset(recognizer)
      IO.inspect(wave, label: "------wave------")
      IO.inspect(result, label: "------result------")
      # :timer.sleep(1000)

       {:noreply, socket}
    {:noreply,  socket}

and this is the error :

1403: heap overflow
             [error] GenServer #PID<0.720.0> terminating
** (ArgumentError) argument error
    (vosk 915e429) :vosk.recognizer_partial_result(#Reference<0.2495677460.3785490434.237916>)
    (pba 0.1.0) lib/pba_web/channels/room_channel.ex:16: PbaWeb.RoomChannel.handle_in/3
    (phoenix 1.7.2) lib/phoenix/channel/server.ex:317: Phoenix.Channel.Server.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{topic: "room:lobby", event: "file_chunk", payload: {:binary, <<235, 255, 223, 255, 229, 255, 252, 255, 21, 0, 33, 0, 65, 0, 34, 0, 0, 0, 251, 255, 3, 0, 9, 0, 15, 0, 10, 0, 246, 255, 4, 0, 10, 0, 29, 0, 49, 0, 54, 0, 51, 0, 49, 0, 35, ...>>}, ref: "705", join_ref: "3"}
State: %Phoenix.Socket{assigns: %{}, channel: PbaWeb.RoomChannel, channel_pid: #PID<0.720.0>, endpoint: PbaWeb.Endpoint, handler: PbaWeb.UserSocket, id: nil, joined: true, join_ref: "3", private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Pba.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "room:lobby", transport: :websocket, transport_pid: #PID<0.713.0>}

I think the best way to handle it is with first-in, first-out but the truth is that I am not understanding how to do this in my project with elixir and that it works with my channels in phoenix.
If you have any idea where I can get detailed information on how to do it, I would be very grateful or a better option. I’m really new to the language and I still don’t fully understand it.

Erlang has a queue module.

You might like to rewrite your if/else if as a case statement. It will read nicer.

What do you mean by that? They are called in different code branches, never together.

Additionally: is handle_in inside Model as well?

the handle_in is inside a channel but I have added the vosk library in my dependencies, locally
And these two functions belong to that library. In addition, the model is also loaded through it, but through a genserver and other functions, but what I think is that they are overlapping each other somewhere, but it is only a theory.

thanks for your help, where can I see more information about the module?