Show real-time process of a function

I currently have a function that returns this

1
2
3
4

1000

I need this interactivity function to be presented in real time on the user’s screen.

button example
Html

<button class="dropdown-item" phx-click="example" phx-target="#example">Exemplo</button>
<%= live_component @socket, ProjectWeb.Example.Modal, id: "modal-one", title: "Test" do %>
  <%= @example %>
<% end %>

Function:

@impl true
def handle_event("example", _, socket) do
  example = function_1()

  {:noreply, assign(socket, example: example)}
end

On my backend I can see the function running normally.
But the user cannot see this.

How do I present this on the user’s screen in real-time?

def work(parent, data) do
  Enum.each(Enum.with_index(data), fn {item, index} ->
    work_on(item)
    send(parent, {:progress, index})
  end)
end

then handle_info in LV

or use Phoenix PubSub

1 Like

Why do You think this will increase?

Calling function_1() without parameters should always return the same result.

How can You have a function that returns something else when You call it? (I know it’s possible, but I am curious about your function_1())