method stable
Documentation for method stable
assembled from the following types:
class Supply
From Supply
(Supply) method stable
method stable(Supply: , : = --> Supply)
Creates a new supply that only passes on a value flowing through the given supply if it wasn't superseded by another value in the given $time
(in seconds). Optionally uses another scheduler than the default scheduler, using the :scheduler
parameter.
To clarify the above, if, during the timeout $time
, additional values are emitted to the Supplier
all but the last one will be thrown away. Each time an additional value is emitted to the Supplier
, during the timeout, $time
is reset.
This method can be quite useful when handling UI input, where it is not desired to perform an operation until the user has stopped typing for a while rather than on every keystroke.
my = Supplier.new;my = .Supply;.tap(-> );.emit(42);my Supply = .stable(5);.tap(-> );sleep(3);.emit(43); # will not be seen by $supply2 but will reset $time.emit(44);sleep(10);# OUTPUT: «Supply1 got: 42Supply1 got: 43Supply1 got: 44Supply2 got: 44»
As can be seen above, $supply1
received all values emitted to the Supplier
while $supply2
only received one value. The 43 was thrown away because it was followed by another 'last' value 44 which was retained and sent to $supply2
after approximately eight seconds, this due to the fact that the timeout $time
was reset after three seconds.