JRuby gives you three options to deal with this situation:
Guard | Triggers Immediately | Description |
---|---|---|
#debounce_for | No | Waits until there is a minimum interval between triggers. |
#throttle_for | No | Rate-limits the executions to a minimum interval, regardless of the interval between triggers. Waits until the end of the period before executing, ignores any leading triggers. |
#only_every | Yes | Rate-limits the executions to a minimum interval. Immediately executes the first trigger, then ignores subsequent triggers for the period. |
To deal with a “Door bell” being pressed repeatedly, use only_every
Example rule:
# They can keep pressing the door bell as often as they like,
# but the bell will only ring at most once every minute
rule "Door Bell is pressed" do
updated DoorBell_Button, to: "single"
only_every 1.minute
run { Audio.play_stream "doorbell.mp3" }
end
Or in a UI rule (just the rule body):
only_every 1.minute do
Audio.play_stream "doorbell.mp3"
end