Iex output does not returns using IO.puts withing genserver functions

Currently getting into OTP, more specifically genservers and intervals.

Having the following code :

defmodule SomeModule do
  use GenServer

  @refetch_interval :timer.seconds(5)

  def start_link(_args), do: GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
  def init(_args), do: {:ok, %{}, {:continue, :fetch}}

  def handle_continue(:fetch, _state) do
    IO.puts("Initial...")
    loop()
  end

  def handle_info(:fetch, _state) do
    IO.puts("Looping...")
    loop()
  end

  defp loop do
    symbols = fetch()
    Process.send_after(self(), :fetch, @refetch_interval)
    {:noreply, symbols}
  end

  defp fetch do
    # some async api call...
  end
end

The iex console outputs kind of hangs :

~/Desktop/tutorials (main)$ iex -S mix
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit] [dtrace]

Compiling 1 file (.ex)
Initial...
Interactive Elixir (1.13.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> Looping...
Looping...
Looping...
Looping...
Looping...
Looping...
Looping...
Looping...
Looping...
Looping... # pressed enter

nil
iex(3)>

As you can see, the first IO.puts returns right away. But others pile up without a clean return.
Expecting a clean return everytime instead, like below :

~/Desktop/tutorials (main)$ iex -S mix
Erlang/OTP 24 [erts-12.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit] [dtrace]

Compiling 1 file (.ex)
Initial...
Interactive Elixir (1.13.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> Looping...
iex(3)> Looping...
iex(4)> 
#etc

as i’m getting started, wondering if i was doing anything wrong (soft blocking pattern somewhere ?)

thanks a lot for any infos about it;

regards

1 Like

You mean that there is no repeated iex> prompt for each output of the GenServer?

1 Like

No that’s how it works, nothing is broken here. iex> prompt reacts only on user input, not the standard output.

4 Likes

thanks a lot for your reply!
at that point it is very helpful to know i’m not missing something