September 2017
Beginner
402 pages
9h 52m
English
In Perl 6, there are special keywords for woking with on-demand supplies. Instead of explicitly creating objects of the Supply class, use the react keyword. Creating a tap is replaced with the whenever block in this case:
react { whenever Supply.interval(0.5) { .say; }}
The program prints number every 0.3 seconds. Notice the major difference with the previous examples. With react, there is no need to call sleep or somehow control the lifecycle of the program after creating a tap. The program runs infinitely until you break it with Ctrl+C, for example.
To break the loop programmatically, call the done function:
react { whenever Supply.interval(0.5) { .say; done if $_ > 3; }}
This time, the program prints the ...
Read now
Unlock full access