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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="apr" data-post="9" data-topic="16859" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/apr/48/11951_2.png" class="avatar"> apr:</div>
<blockquote>
<p>So <a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a>, you’d consider managing priority state explicitly via queues stored in GenServer state bad practice? I want to use elixir modules as much as I can and managing priority manually doesn’t seem too hard.</p>
</blockquote>
</aside>
<p>Not necessarily, but you’d need to have both cast’s and call’s return immediately with a 0-sleep, so that all messages will be received and buffered and then you can handle a given message in the 0-sleep timeout function.</p>
<aside class="quote no-group" data-username="NobbZ" data-post="10" data-topic="16859" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/48/27235_2.png" class="avatar"> NobbZ:</div>
<blockquote>
<p>Creating and managing a priority queue which you update on new messages is probably more expensive than just processing the messages in order.</p>
</blockquote>
</aside>
<p>In general absolutely this, but there are definite use-cases where a priority queue is very important.</p>
<aside class="quote no-group" data-username="peerreynders" data-post="11" data-topic="16859">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/48/5826_2.png" class="avatar"> peerreynders:</div>
<blockquote>
<p>If the priority management process uses a blocking <a href="https://hexdocs.pm/elixir/GenServer.html#call/3" rel="noopener nofollow ugc"> <code>call/3</code> </a> to the GenServer it wouldn’t select the next message from the process mailbox until the <code>call</code> returns.</p>
</blockquote>
</aside>
<p>You don’t have to return a message to a call immediately, you are just supposed to do it ‘sometime within the timeout’.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" 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="98631" 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/message-prioritization-inside-genserver/16859/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-98631" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="98631"
                     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="98632" data-post-id="98632">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="OvermindDL1" data-post="12" data-topic="16859">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>but you’d need to have both cast’s and call’s return immediately with a 0-sleep, so that all messages will be received and buffered</p>
</blockquote>
</aside>
<p>Alternately promote the priority of messages-in-waiting in order to return most, if not all responses “sometime within the timeout”- which means “managing priority” becomes much more complicated and is tightly coupled to what the GenServer is <em>actually</em> doing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="98632" 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/message-prioritization-inside-genserver/16859/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-98632" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="98632"
                     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="369882" data-post-id="369882">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="axelson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/axelson/120/26351_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  axelson
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Scenic Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="apr" data-post="1" data-topic="16859">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/apr/48/11951_2.png" class="avatar"> apr:</div>
<blockquote>
<p>Is there a way to send a message to a Genserver process such that the message skips all other messages in the genserver’s message queue, and will be the next message to be processed?</p>
</blockquote>
</aside>
<p>For anyone that comes here from search like I have, Erlang/OTP 28 now supports this: <a href="https://www.erlang.org/blog/highlights-otp-28/#priority-messages" class="inline-onebox" rel="nofollow">Erlang/OTP 28 Highlights - Erlang/OTP</a></p>
<blockquote>
<h1>Priority Messages</h1>
<p>Sometimes, it is important for urgent messages to <em>skip the queue</em> and be read by the receiving process as soon as possible. Erlang/OTP 28 introduces priority messages, an opt-in mechanism that allows the receiving process to let certain messages get priority status.</p>
</blockquote>
<p>I haven’t tried to use this from Elixir yet, but it ought to work.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="369882" data-batch-url="/posts/batch_likers">
                        2
                      </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/message-prioritization-inside-genserver/16859/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-369882" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="369882"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></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>