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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This looks pretty interesting, great work!</p>
<aside class="quote no-group" data-username="Azolo" data-post="1" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>WebSockex strives to work as a OTP special process</p>
</blockquote>
</aside>
<p>Out of curiosity, why did you roll your own special process, instead of using e.g. GenServer?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35408" 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/websockex-an-elixir-websocket-client/4733/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-35408" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35408"
                     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="35453" data-post-id="35453">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                    <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">
								<aside class="quote no-group" data-username="sasajuric" data-post="12" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/48/991_2.png" class="avatar"> sasajuric:</div>
<blockquote>
<p>Out of curiosity, why did you roll your own special process, instead of using e.g. GenServer?</p>
</blockquote>
</aside>
<p>It’s because I’m too curious for my own good.</p>
<p>When I realized, “Oh right, this should play nice with OTP.” I decided to learn what made a process “special” instead of just putting it in a <code>GenServer</code>.</p>
<p>There was a point where I was frustrated and started to roll it into a <code>GenServer</code>, but at that point I also realized the design choice that was frustrating me and changed 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="35453" 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/websockex-an-elixir-websocket-client/4733/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-35453" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35453"
                     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="35454" data-post-id="35454">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="idi527" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  idi527
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If it’s not much of a bother, could you briefly explain how it is different from <code>websocket_client</code> [0]?</p>
<p>[0] <a href="https://github.com/sanmiguel/websocket_client" class="inline-onebox" rel="noopener nofollow ugc">GitHub - sanmiguel/websocket_client: Erlang websocket client (ws and wss supported) · GitHub</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="35454" 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/websockex-an-elixir-websocket-client/4733/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-35454" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35454"
                     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="35458" data-post-id="35458">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                    <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>Sure, but first let me say there are two different <code>websocket_client</code> repos that I used.</p>
<p>The first one was the one <a href="https://hex.pm/packages/websocket_client" rel="nofollow">listed on hex.pm</a>(which is the one you linked). It implements <code>gen_fsm</code> and it more actively maintained. However, there are also a couple bugs. Most of them were already reported issues, but one in particular was that terminate was being called consistently in one of my cases. However it was fickle and I had problems reproducing it, but it was causing my tests to fail 1/15 times. So when I tried to jump and trace it, I was overwhelmed by the sheer number of things the repo was trying to do.</p>
<p>So I looked at the <a href="https://github.com/jeremyong/websocket_client" rel="noopener nofollow ugc">original fork</a>. It didn’t have any of the bugs I experienced but also wasn’t an OTP special process and didn’t wait for the server to close the socket (as per the spec). I think I also had some problems with <code>close</code> frames that contained a payload. But this repo is no longer maintained in favor of the one above.</p>
<p>So, I decided to to write my own. I wanted it to be some where in between. Being compatible with OTP, but simple enough that someone could jump into and be able to submit simple bug-free code without being overwhelmed.</p>
<p>Also, <code>WebSockex</code> is has great test coverage. <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" 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="35458" 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/websockex-an-elixir-websocket-client/4733/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-35458" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35458"
                     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="35460" data-post-id="35460">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The remark that it implements special process by hand made me interested, so I had a look at the code. Here are some things I spotted, I hope you don’t mind.</p>
<ul>
<li>you don’t handle the regular naming conventions - it would be nice to be able to pass the <code>name</code> option like with all the Elixir’s stdlib behaviours. When you do this, there are some race conditions to consider, so I would advise looking at using the <code>:gen</code> module that powers all the Erlang behaviours (it’s not documented publicly, but I saw many projects using it, I’m not sure how bad of an idea that is - but it definitely handles a lot of common scenarios).</li>
<li>whenever you call user module callbacks, they should be wrapped in a <code>try</code> and errors should be handled appropriately (e.g. you want to call the terminate callback in that case before dying).</li>
<li>it’s nice to use <code>:sys.handle_debug</code> for any messages received and sent out (or any “major” events that happen in a process) - this is really useful when things go wrong.</li>
<li>in the receive loop, you probably want to look for the <code>{:EXIT, parent, reason}</code> message in case the user starts trapping exits in the process. The special process has to exit with the same reason as the parent in case that happens.</li>
<li>it looks like you don’t implement the <code>system_code_change/4</code> callback</li>
<li>there’s an additional <code>format_status/2</code> callback you can implement to control what information is returned on <code>:sys.get_status</code> and <code>:sys.get_state</code> used, for example, by observer.</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35460" 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/websockex-an-elixir-websocket-client/4733/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-35460" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35460"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="35489" data-post-id="35489">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Azolo" data-post="13" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>It’s because I’m too curious for my own good.</p>
<p>When I realized, “Oh right, this should play nice with OTP.” I decided to learn what made a process “special” instead of just putting it in a GenServer.</p>
</blockquote>
</aside>
<p>I absolutely appreciate and encourage trying different things, and even overcomplicating the code for the purpose of learning and gaining a deeper understanding. That being said, if learning is the only motivation for using your own special process here, and assuming that this library is meant to be used by others and contributed to, I think it might be wise to switch to GenServer. Doing this would make it easier to solve (and in some cases automatically solve) issues mentioned by <a class="mention" href="/u/michalmuskala" rel="nofollow">@michalmuskala</a>.</p>
<p>It might also simplify some future additions. For example, I think that calls should be supported as well, and this would be pretty simple if the process was a GenServer. Making the interface of your behaviour more similar to GenServer by supporting timeouts and hibernate options in return tuples, as well as stop option would also be nice. Again, this should be fairly trivial if your behaviour was powered by GenServer.</p>
<aside class="quote no-group" data-username="Azolo" data-post="15" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>The first one was the one listed on hex.pm(which is the one you linked). It implements gen_fsm and it more actively maintained. However, there are also a couple bugs. Most of them were already reported issues, but one in particular was that terminate was being called consistently in one of my cases. However it was fickle and I had problems reproducing it, but it was causing my tests to fail 1/15 times. So when I tried to jump and trace it, I was overwhelmed by the sheer number of things the repo was trying to do.</p>
</blockquote>
</aside>
<p>I have similar sentiments about the current state of WS clients. About a year ago, I looked into a couple of them, and wasn’t really completely pleased with any. In the end, I settled for <a href="https://github.com/sanmiguel/websocket_client" rel="noopener nofollow ugc">this branch</a>. I like that your project starts with a clean slate, and has good test coverage. That seems very promising!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35489" 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/websockex-an-elixir-websocket-client/4733/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-35489" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35489"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="35502" data-post-id="35502">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                    <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>Awesome feedback, thanks a ton. A couple of other things I didn’t mention or am starting to remember now.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>you don’t handle the regular naming conventions - it would be nice to be able to pass the <code>name</code> option like with all the Elixir’s stdlib behaviours. When you do this, there are some race conditions to consider, so I would advise looking at using the :gen module that powers all the Erlang behaviours (it’s not documented publicly, but I saw many projects using it, I’m not sure how bad of an idea that is - but it definitely handles a lot of common scenarios).</p>
</blockquote>
</aside>
<p>So the <code>:gen</code> module implements the <code>call</code> behavior. Which I had a really long thought process where I didn’t really want to have any synchronous calls because of the behavior of WebSockets and the way reconnects are implemented. That may change in the future but for now I don’t want any thing that can Timeout.</p>
<p>But I don’t mind adding a <code>:name</code> option. That actually doesn’t look too hard.</p>
<p>In the <code>:gen</code> module it looks like it checks during <code>start</code> and then again during the <code>init</code> function when it tries to register the process.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>whenever you call user module callbacks, they should be wrapped in a try and errors should be handled appropriately (e.g. you want to call the terminate callback in that case before dying).</p>
</blockquote>
</aside>
<p>Ahh, good point. I did that for <a href="https://github.com/Azolo/websockex/blob/master/lib/websockex.ex#L481-L484" rel="noopener nofollow ugc">some of them</a>, but I don’t think that it’s tested and it isn’t consistent.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>it’s nice to use <code>:sys.handle_debug</code> for any messages received and sent out (or any “major” events that happen in a process) - this is really useful when things go wrong.</p>
</blockquote>
</aside>
<p>Yeah, that is me being lazy. I also need to add an error message on exit.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>in the receive loop, you probably want to look for the <code>{:EXIT, parent, reason}</code> message in case the user starts trapping exits in the process. The special process has to exit with the same reason as the parent in case that happens.</p>
</blockquote>
</aside>
<p>I totally didn’t know that. Thanks.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>it looks like you don’t implement the <code>system_code_change/4</code> callback</p>
</blockquote>
</aside>
<p>Oops. Thanks, incidentally I have no idea how to test this.</p>
<aside class="quote no-group" data-username="michalmuskala" data-post="16" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/48/20288_2.png" class="avatar"> michalmuskala:</div>
<blockquote>
<p>there’s an additional format_status/2 callback you can implement to control what information is returned on :sys.get_status and :sys.get_state used, for example, by observer.</p>
</blockquote>
</aside>
<p>This is me being lazy again. <img src="https://forum.elixirforum.com/images/emoji/apple/zipper_mouth.png?v=15" title=":zipper_mouth:" class="emoji" alt=":zipper_mouth:" loading="lazy" width="20" height="20"></p>
<p>Thanks again for the advice!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35502" 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/websockex-an-elixir-websocket-client/4733/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-35502" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35502"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="35505" data-post-id="35505">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Azolo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Azolo/120/2189_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Azolo
                    <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">
								<aside class="quote no-group" data-username="sasajuric" data-post="17" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/48/991_2.png" class="avatar"> sasajuric:</div>
<blockquote>
<p>Making the interface of your behaviour more similar to GenServer by supporting timeouts and hibernate options in return tuples, as well as stop option would also be nice.</p>
</blockquote>
</aside>
<p>This made me remember why I didn’t use <code>GenServer</code>. I didn’t want those behaviors to be available because it could mess the handling of the control frames and I didn’t want to move the WebSocket into another child process.</p>
<p>I had the idea of writing another module based off <code>GenServer</code> that would wrap a <code>WebSockex</code> connection. This would make doing complex things like synchronous sends possible without messing too much with the flow that the WebSocket spec asks for.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35505" 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/websockex-an-elixir-websocket-client/4733/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-35505" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35505"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="35507" data-post-id="35507">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Azolo" data-post="18" data-topic="4733" 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/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>So the <code>:gen</code> module implements the <code>call</code> behavior. Which I had a really long thought process where I didn’t really want to have any synchronous calls because of the behavior of WebSockets and the way reconnects are implemented. That may change in the future but for now I don’t want any thing that can Timeout.</p>
</blockquote>
</aside>
<p>The fact that <code>call</code> is synchronous for the caller, does not mean it’s synchronous for the server. Using an explicit <code>GenServer.reply/1</code> you can reply to the message before returning from the <code>handle_call</code> function, after or even from a completely different process.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35507" 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/websockex-an-elixir-websocket-client/4733/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-35507" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35507"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="35517" data-post-id="35517">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Azolo" data-post="19" data-topic="4733">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/azolo/48/2189_2.png" class="avatar"> Azolo:</div>
<blockquote>
<p>This made me remember why I didn’t use GenServer. I didn’t want those behaviors to be available because it could mess the handling of the control frames and I didn’t want to move the WebSocket into another child process.</p>
</blockquote>
</aside>
<p>Just because your behaviour is internally powered by GenServer doesn’t mean it has to expose everything GenServer does. So for example, if the timeout option doesn’t make sense in WebSockex, you don’t need to support it in your own behaviour.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="35517" 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/websockex-an-elixir-websocket-client/4733/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-35517" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="35517"
                     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 #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/4733/load_more?page=3">Load more posts (33 remaining)</a>
</div></template></turbo-stream>