Thanks for the explanation!

A December 30, 2020 3:28:24 PM UTC, Gianni Ceccarelli <dak...@thenautilus.net> 
escreveu:
>On 2020-12-30 David Santiago <deman...@gmail.com> wrote:
>> Thanks! It's indeed much clearer. However i have a question, why the 
>> react on line 24?
>> 
>> The react there isn't required right?
>
>I think it is ☺ The code, without the debugging bits::
>
>    react {
>        whenever $channel -> $val {
>            $conn.print("SENDING\r\n");
>
>            react {
>                whenever $conn-supply -> $line {
>                    if $line ~~ /^340/ {
>                        $conn.print("[$consumer]: value $val\r\n");
>                    } else {
>                        done;
>                    }
>                }
>            }
>        }
>    }
>
>I read this as:
>
>* loop as long as the channel has values, then exit
>* for each value in the channel:
>  * write to the server
>  * then loop reading from the server
>  * and exit *this inner loop* when you get a non-340 line
>
>Without the second ``react``, that ``done`` would exit the first ``react``,
>essentially terminating the client. There's probably a way to write
>the whole thing differently (keeping more explicit state, probably).
>
>Also, my understanding of ``whenever`` is that it's adding a hook into
>the event loop, and only leaving the surrounding ``react`` (or
>``supply``) will remove that hook (people who understand this better
>than I do: please correct me!). If that's true, adding a hook many
>times on the same condition looks wrong to me…
>    
>-- 
>       Dakkar - <Mobilis in mobile>
>       GPG public key fingerprint = A071 E618 DD2C 5901 9574
>                                    6FE2 40EA 9883 7519 3F88
>                           key id = 0x75193F88
>

-- 
Sent from my phone with K-9 Mail. Please excuse my brevity.

Reply via email to