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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rogach" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rogach
                    <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">
								<blockquote>
<p>These might be signs that the <code>LineReader</code> would be better off as its own process i.e. Task/Agent/Genserver so it can keep track of its own state. I’d be curious what else it’s being used for and how else it’s being used.</p>
</blockquote>
<p>Yes, I thought about such approach, but feels very heavy-weight. As I understand it you have to link that additional process into the supervision hierarchy, figure out how to pass it’s pid to the “main” process, transition the resources to the additional process (the socket port in this case) - that’s like two pages of code, too much.</p>
<blockquote>
<p>or rolled into <code>ClientHandler</code></p>
</blockquote>
<p>It’s used in several places, not only in the ClientHandler, so I wanted to avoid code duplication. In this case it’s not much, maybe 10 lines, but these lines better be carefuly tested.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="327059" 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/is-mutating-parent-state-in-a-module-an-anti-pattern/63276/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-327059" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="327059"
                     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="327133" data-post-id="327133">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="codeanpeace" data-post="11" data-topic="63276">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/codeanpeace/48/10278_2.png" class="avatar"> codeanpeace:</div>
<blockquote>
<p>These might be signs that the <code>LineReader</code> would be better off as its own process i.e. Task/Agent/Genserver so it can keep track of its own state or rolled into <code>ClientHandler</code>. I’d be curious what else it’s being used for and how else it’s being used.</p>
</blockquote>
</aside>
<p>Imo processes should only be introduced if there are runtime level reasons for them - failure isolation, asynchronous processing, … That is completely separate from code level abstractions, where multiple module collaborate to build up logic.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="327133" data-batch-url="/posts/batch_likers">
                        5
                      </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/is-mutating-parent-state-in-a-module-an-anti-pattern/63276/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-327133" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="327133"
                     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="327160" data-post-id="327160">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, agreed – it’s what I was trying to suss out with “what else it’s being used for and how else it’s being used”. It’d be the <a href="https://hexdocs.pm/elixir/1.16.2/process-anti-patterns.html#code-organization-by-process" rel="noopener nofollow ugc">code organization by process anti-pattern</a> otherwise.</p>
<aside class="quote no-group" data-username="rogach" data-post="12" data-topic="63276">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/r/5f8ce5/48.png" class="avatar"> rogach:</div>
<blockquote>
<p>As I understand it you have to link that additional process into the supervision hierarchy, figure out how to pass it’s pid to the “main” process, transition the resources to the additional process (the socket port in this case) - that’s like two pages of code, too much.</p>
</blockquote>
</aside>
<p>You can spin up a temporary process “on demand” e.g. <a href="https://hexdocs.pm/elixir/1.16.2/Task.html#async/1" rel="noopener nofollow ugc"><code>Task.async/1</code></a> and “if you spawn a task inside a <code>GenServer</code>, then the <code>GenServer</code> will automatically await for you and call <code>GenServer.handle_info/2</code> with the task response and associated <code>:DOWN</code> message.”</p>
<p>If the data packet processing logic is brittle and the client handler needs to be robust, a nice runtime reason could be failure isolation so that packet processing can fail without affecting the client handler. You’d likely want to <a href="https://hexdocs.pm/elixir/1.16.2/process-anti-patterns.html#sending-unnecessary-data" rel="noopener nofollow ugc">only pass the necessary information</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="327160" 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/is-mutating-parent-state-in-a-module-an-anti-pattern/63276/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-327160" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="327160"
                     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>