In Concurrency§
See primary documentation in context for whenever
The whenever
keyword can be used in supply blocks or in react blocks. From the 6.d version, it needs to be used within the lexical scope of them. It introduces a block of code that will be run when prompted by an asynchronous event that it specifies - that could be a Supply
, a Channel
, a Promise
or an Iterable
.
Please note that one should keep the code inside the whenever
as small as possible, as only one whenever
block will be executed at any time. One can use a start
block inside the whenever
block to run longer running code.
In this example we are watching two supplies.
my = Supplier.new;my = Supplier.new;my = supply.tap( -> );.emit("Radish"); # OUTPUT: «We've got a vegetable: Radish».emit("Thick sliced"); # OUTPUT: «We've got bread: Thick sliced».emit("Lettuce"); # OUTPUT: «We've got a vegetable: Lettuce»