<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eyal Shalev</title>
    <description>The latest articles on DEV Community by Eyal Shalev (@eyalshalev).</description>
    <link>https://dev.to/eyalshalev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F702089%2F8814e6db-8558-4527-be59-8b83c4ab112b.jpeg</url>
      <title>DEV Community: Eyal Shalev</title>
      <link>https://dev.to/eyalshalev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eyalshalev"/>
    <language>en</language>
    <item>
      <title>Introducing Async Channels</title>
      <dc:creator>Eyal Shalev</dc:creator>
      <pubDate>Sat, 09 Oct 2021 13:44:04 +0000</pubDate>
      <link>https://dev.to/eyalshalev/introducing-async-channels-333n</link>
      <guid>https://dev.to/eyalshalev/introducing-async-channels-333n</guid>
      <description>&lt;h2&gt;
  
  
  What?
&lt;/h2&gt;

&lt;p&gt;Channels are queue-like objects &lt;em&gt;(First In First Out)&lt;/em&gt; that their &lt;code&gt;enqueue&lt;/code&gt; (send) and &lt;code&gt;dequeue&lt;/code&gt; (get) functions are asynchronous (&lt;code&gt;async&lt;/code&gt;). By passing them between asynchronous functions we can synchronize operations between said functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;Let's say we want to process a large chunk of data &lt;em&gt;(simulated by a several lorem-ipsum paragraphs)&lt;/em&gt;.&lt;br&gt;
Some of the processes that we want to perform on that data are fast, while other are time (and resource) consuming.&lt;br&gt;
To avoid overwhelming our infrastructure, we want to make not to send data to a process that isn't ready to accept new data. In other words, we want to implement &lt;a href="https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7"&gt;back-preasure&lt;/a&gt;.&lt;br&gt;
This is where &lt;strong&gt;Async Channels&lt;/strong&gt; come into play.&lt;/p&gt;

&lt;p&gt;When you &lt;code&gt;send&lt;/code&gt; (or &lt;code&gt;get&lt;/code&gt;) a message to (or from) a channel, it returns a promise.&lt;br&gt;
For &lt;code&gt;send&lt;/code&gt; requests, it will resolve if the channel has available buffer, or (if not), after a &lt;code&gt;get&lt;/code&gt; is performed on the channel.&lt;br&gt;
And on the opposite side, a &lt;code&gt;get&lt;/code&gt; request will resolve if there is buffered message on the channel, or after a &lt;code&gt;send&lt;/code&gt; request is made.&lt;/p&gt;
&lt;h2&gt;
  
  
  How?
&lt;/h2&gt;

&lt;p&gt;Below is an example usage of &lt;strong&gt;async_channels&lt;/strong&gt;, where long processes are simulated by calling &lt;code&gt;sleep&lt;/code&gt; (a helper function that returns a promise that is resolved after &lt;code&gt;n&lt;/code&gt; seconds).&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Eyal-Shalev/embed/xxLKjwR?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;br&gt;&lt;br&gt;
You can view the documentation on &lt;a href="https://eyal-shalev.github.io/async_channels"&gt;eyal-shalev.github.io/async_channels&lt;/a&gt;&lt;br&gt;

&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Eyal-Shalev"&gt;
        Eyal-Shalev
      &lt;/a&gt; / &lt;a href="https://github.com/Eyal-Shalev/async_channels"&gt;
        async_channels
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Inspired by Go &amp;amp; Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>library</category>
      <category>async</category>
      <category>channels</category>
    </item>
  </channel>
</rss>
