<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="223048" data-post-id="223048">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rvirding" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rvirding/120/1409_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rvirding
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Erlang</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It is not really the <code>handle_info</code> callback which processes the actual <strong>message</strong>. The GenServer has a top-loop which sits and receives messages arriving at the process. When a message arrives it checks the message format and and calls the relevant callback to handle the message. When the callback returns it goes back into the top-loop and waits for and then processes the next message aand then waits for the next one and then … . In your case it calls the <code>handle_info</code> callback with the message.</p>
<p>This means that there is no real buffering of messages in the GenServer message queue so checking its length will generally return a small number. The only time the queue can become long is if the GenServer becomes overloaded.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="223048" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/monitoring-messages-in-process-mailboxes/41489/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-223048" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="223048"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="223126" data-post-id="223126">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vrod" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vrod
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you for the explanation! This is making sense as I study it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="223126" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/monitoring-messages-in-process-mailboxes/41489/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-223126" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="223126"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="223173" data-post-id="223173">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is worth reading : <a href="http://erlang.org/pipermail/erlang-questions/2011-April/057777.html" class="inline-onebox" rel="nofollow">[erlang-questions] The gen server simplified (how it works)</a></p>
<p>I made an Elixir version of the mini genserver for you, with small changes to demonstrate how handle_info works:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MiniGs do
  def start_link(module, arg) do
    pid = spawn_link(fn -&gt; start(module, arg) end)
    {:ok, pid}
  end

  def call(pid, request, timeout \\ 5000) do
    ref = make_ref()
    send(pid, {:minigs_call, self(), ref, request})

    receive do
      {^ref, reply} -&gt; reply
    after
      timeout -&gt; exit({:timeout, {MiniGs, :call, [pid, request, timeout]}})
    end
  end

  defp start(module, arg) do
    {:ok, state} = module.init(arg)
    loop(module, state)
  end

  defp loop(module, state) do
    receive do
      {:minigs_call, from, ref, request} -&gt;
        {:reply, reply, new_state} = module.handle_call(request, from, state)
        send(from, {ref, reply})
        loop(module, new_state)

      other_message -&gt;
        {:noreply, new_state} = module.handle_info(other_message, state)
        loop(module, new_state)
    end
  end
end

defmodule Stack do
  def start_link(base) when is_list(base) do
    MiniGs.start_link(__MODULE__, base)
  end

  def push(pid, item) do
    :ok = MiniGs.call(pid, {:push, item})
  end

  def pop(pid) do
    MiniGs.call(pid, :pop)
  end

  def init(base) do
    {:ok, _stack = base}
  end

  def handle_call({:push, item}, _from, stack) do
    {:reply, :ok, [item | stack]}
  end

  def handle_call(:pop, _from, [item | stack]) do
    {:reply, {:ok, item}, stack}
  end

  def handle_call(:pop, _from, []) do
    {:reply, {:error, :empty}, []}
  end

  def handle_info(info, stack) do
    IO.puts("got info: #{inspect(info)}")
    {:noreply, stack}
  end
end

{:ok, pid} = Stack.start_link([])
:ok = Stack.push(pid, 1)
:ok = Stack.push(pid, 2)
:ok = Stack.push(pid, 3)
{:ok, 3} = Stack.pop(pid)
{:ok, 2} = Stack.pop(pid)
{:ok, 1} = Stack.pop(pid)
send(pid, "hello")
{:error, :empty} = Stack.pop(pid)

</code></pre>
<p>As an exercise, you could try to implement the possibility to return timeout as in <code>{:reply, reply, state, timeout}</code> and the mini gs would call <code>module.handle_info(:timeout, state)</code> <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="223173" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/monitoring-messages-in-process-mailboxes/41489/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-223173" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="223173"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="223336" data-post-id="223336">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vrod" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vrod
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Wowwwwww, this is very much educational! Thank you for the very thorough reply!  I appreciate your efforts to educate me!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="223336" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/monitoring-messages-in-process-mailboxes/41489/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-223336" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="223336"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="331063" data-post-id="331063">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="nathanl" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nathanl/120/39891_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  nathanl
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I haven’t used this yet, but as of OTP 27.0, you can subscribe to notifications about mailbox lengths.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">:erlang.system_monitor(self(), [{:long_message_queue, {disable, enable}}])
</code></pre>
<p><code>disable</code> and <code>enable</code> are integer thresholds for when you want receive a message. More explanation is <a href="https://www.erlang.org/doc/apps/erts/erlang.html#system_monitor/2" rel="nofollow">in the docs</a>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="331063" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/monitoring-messages-in-process-mailboxes/41489/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-331063" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="331063"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>