
BernardK
Programming Ruby 3.2 (5th Edition): B1.0 page 205, Only then do we create
page 205, paragraph after the code, line 2 :
then blocks at Ractor.receive. Only then do we create the reading ractor
Because of “Only then” I thought that creating the second Ractor could only take place when the first is waiting on receive
. But the trace shows that both Ractors are created, then the blocks are scheduled.
On page 204 (par. 5, code for one, line 1) I liked “Moving down the file”, for a possible replacement of “Only then”.
Having said that, it’s impressive to see the reader sending several times without waiting for a take.
def displayWord(p_word)
p_word.nil? ? "^nil^" : "|#{p_word}|"
end
puts "*** (main) about to create counter"
counter = Ractor.new(name: "counter") do
puts ">>> ccccc in counter block"
result = Hash.new(0)
while (word = Ractor.receive)
puts "ccccc in counter received word=#{displayWord(word)}"
result[word] += 1
puts "ccccc looping"
end
puts "ccccc in counter while ended word=#{displayWord(word)}"
result
end
puts "*** (main) about to create reader"
Ractor.new(counter, name: "reader") do |counter|
puts ">>> rrrrr in reader block"
File.foreach("testfile") do |line|
puts "rrrrr line=#{line}"
line.scan(/\w+/) do |word|
puts "rrrrr about to send word=#{displayWord(word)}"
counter.send(word.downcase)
puts "rrrrr after send"
end
end
puts "rrrrr about to send nil"
counter.send(nil)
end
puts "*** (main) about to take counter"
counts = counter.take
counts.keys.sort.each { |k| print "#{k}:#{counts[k]} " }
puts
% ruby -w ractor_word_count_flipped.rb
*** (main) about to create counter
<internal ... experimental ...
*** (main) about to create reader
*** (main) about to take counter
>>> ccccc in counter block
>>> rrrrr in reader block
rrrrr line=This is line one
rrrrr about to send word=|This|
rrrrr after send
rrrrr about to send word=|is|
rrrrr after send
rrrrr about to send word=|line|
ccccc in counter received word=|this|
...
First Post!

noelrappin
Author of Modern Front-End Development for Rails
Thanks!
Popular Pragmatic Bookshelf topics

Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New

Hi Brian,
Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New

I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here.
...
New

Hi Jamis,
I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019.
This test doesn’t pass for me:
...
New

First, the code resources:
Page 237: rumbl_umbrella/apps/rumbl/mix.exs
Note: That this file is missing.
Page 238: rumbl_umbrella/app...
New

On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New

I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New

Hey there,
I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
New

On page 78 the following code appears:
<%= link_to ‘Destroy’, product,
class: ‘hover:underline’,
method: :delete,
data: { confirm...
New

I am using Android Studio Chipmunk | 2021.2.1 Patch 2
Build #AI-212.5712.43.2112.8815526, built on July 10, 2022
Runtime version: 11.0....
New
Other popular topics

New

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New

Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New

Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New

Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New

A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New

We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New

Large Language Models like ChatGPT say The Darnedest Things.
The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Author Spotlight:
Peter Ullrich
@PJUllrich
Data is at the core of every business, but it is useless if nobody can access and analyze ...
New

Hello,
I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /ocaml
- /react
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /textmate
- /sublime-text
- /nixos
- /debian
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /spring
- /manjaro
- /django
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /markdown