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
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
Hi,
build fails on:
bracket-lib = “~0.8.1”
when running on Mac Mini M1 Rust version 1.5.0:
Compiling winit v0.22.2
error[E0308]: mi...
New
Title: Web Development with Clojure, Third Edition, vB17.0 (p9)
The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
I ran this command after installing the sample application:
$ cards add do something --owner Brian
And got a file not found error:
Fil...
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
@noelrappin
Running the webpack dev server, I receive the following warning:
ERROR in tsconfig.json
TS18003: No inputs were found in c...
New
Running mix deps.get in the sensor_hub directory fails with the following error:
** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
It seems the second code snippet is missing the code to set the current_user:
current_user: Accounts.get_user_by_session_token(session["...
New
Title: Agile Web Development with Rails 7: (page 70)
I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
Other popular topics
Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness.
https://f...
New
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
Create efficient, elegant software tests in pytest, Python's most powerful testing framework.
Brian Okken @brianokken
Edited by Kat...
New
This is going to be a long an frequently posted thread.
While talking to a friend of mine who has taken data structure and algorithm cou...
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
Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
Author Spotlight:
Bruce Tate
@redrapids
Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
A concise guide to MySQL 9 database administration, covering fundamental concepts, techniques, and best practices.
Neil Smyth
MySQL...
New
Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /rails
- /js
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /html
- /centos
- /php
- /deepseek
- /zig
- /scala
- /sublime-text
- /textmate
- /lisp
- /react-native
- /nixos
- /debian
- /agda
- /kubuntu
- /arch-linux
- /django
- /deno
- /ubuntu
- /revery
- /nodejs
- /manjaro
- /spring
- /diversity
- /lua
- /julia
- /slackware
- /c







