Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/cftbat/core-async.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h3>Buffering</h3>

<p class="Body">(Be careful evaluating the last <code>(&gt;!! echo-buffer "ketchup")</code> because it will <span>block your REPL. If you’re using a Leiningen REPL, </span><span class="Keycap">ctrl-C</span><span> will unblock it.)</span></p>
<p class="Body">In this case, you’ve created a channel with buffer size 2. That means you can put two values on the channel without waiting, but putting a third <span>one on means the process will wait until another process takes a value </span>from the channel. You can also create<em> sliding </em>buffers with <code>sliding-buffer</code>, which drops values in a first-in, first-out fashion; and <em>dropping</em> buffers with <code>dropping-buffer</code>, which discards values in a last-in, first-out fashion. Neither of these buffers will ever cause <code>&gt;!!</code> to block.</p>
<p class="Body"><span>By using buffers, the master ketchup chef can keep whipping up batches of mouthwatering ketchup without having to wait for his staff to take them away. If he’s using a regular buffer, it’s like he has a shelf to put all his ketchup batches on; once the shelf is full, he’ll still have to wait for space to open up. If he’s using a sliding buffer, he’d throw away the oldest batch of ketchup when the shelf is full, slide all the ketchup down, and put the new batch in the vacant space. With a dropping buffer, he’d just </span>knock the freshest batch off of the shelf and put his new batch in that space.</p>
<p class="Body"><span>By using buffers, the master ketchup chef can keep whipping up batches of mouthwatering ketchup without having to wait for his staff to take them away. If he’s using a regular buffer, it’s like he has a shelf to put all his ketchup batches on; once the shelf is full, he’ll still have to wait for space to open up. If he’s using a sliding buffer, he’d throw away the oldest batch of ketchup when the shelf is full, slide all the ketchup down, and put the new batch in the vacant space. With a dropping buffer, he’d just throw away the new batch he has just made if the shelf is full.</span></p>
<p class="Body">Buffers are just elaborations of the core model: processes are independent, concurrently executing units of logic that respond to events. You can create processes with go blocks and communicate events over channels.</p>
<h3>Blocking and Parking </h3>
<p class="BodyFirst">You may have noticed that the take function <code>&lt;!</code> used only one exclamation point, whereas the put function <code>&gt;!!</code> used two. In fact, both put and take have one-exclamation-point and two-exclamation-point varieties. When do you use which? The simple answer is that you can use one exclamation point inside go blocks, but you have to use two exclamation points outside of them:</p>
Expand Down