Javaru

Javaru

Kotlin Coroutine Confidence: Add `parallel/v9` (pg 125)

When I ran the parallel/v8 example on page 125, I did not get the results described of not seeing the timer’s output until the program almost exits. I got the timer output right from the start, and every second thereafter. After a few minutes of trying to figure out why, I gave up and kept reading. Once I got to page 126, I saw why. It was because the slowHash() function was already a suspend function with the yield() in it. This is shown as a change to the code on page 126, but it was not a change since it was already present in the downloaded code, and therefore present for the run on page 125. Thus the different result.

Since I am running each example as soon as I first encounter it, (and up to this point it has always worked doing that :slight_smile:) this is unexpected behavior. As I said, I spent a few minutes trying to figure things out. I didn’t even look a the slowHash() function since it wasn’t a point of discussion. (And I’m not sure I would have noticed the issue had I looked at the function since that function is not discussed in v8 until it is modified on page 126.)

As a suggestion, I think the changes to the slowHash() function on page 126 should be broken out to a parallel/v9 instance. And the parallel/v8 slowHash() function should not be a suspend function or have the yield(). That way the “bad” result occurs when the code is run on page 125. Another option is to just not include the suspend and yield() in the parallel/v8 version and have the user make the change in their code when they read page 126. But that may be less desirable since until now, there have not been any code changes needed by the user, and it breaks the “incremental versions” paradigm in use. (And it may prevent you from testing things properly),

Assuming you go with a v9, then the sentence:

Run either of the two previous programs again with this upgraded slowHash()
function, and everything works the way we wanted. Our extra timer coroutine can print its output every one second, and our timeout code can cancel the work promptly.

can change to something like:

You can also run the previous timeout program with this upgraded slowHash()
function, and everything will work the way we wanted. Our timeout code can cancel the work promptly.

book-kotlin-coroutine-confidence version B3

Popular Prag Prog topics Top

johnp
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
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
AleksandrKudashkin
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
New
dsmith42
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
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New

Other popular topics Top

AstonJ
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
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
New
New
AstonJ
Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry: He left this note on Twitter on the weekend: And one...
New

Latest in PragProg

View all threads ❯