Class: Webmidi::Middleware::Throttle
- Defined in:
- lib/webmidi/middleware/timing_gate.rb
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize(app, interval:, **options) ⇒ Throttle
constructor
A new instance of Throttle.
Constructor Details
#initialize(app, interval:, **options) ⇒ Throttle
Returns a new instance of Throttle.
34 35 36 37 38 39 |
# File 'lib/webmidi/middleware/timing_gate.rb', line 34 def initialize(app, interval:, **) super(app, **) validate_interval!(interval) @interval = interval @last_sent = nil end |
Instance Method Details
#call(message) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/webmidi/middleware/timing_gate.rb', line 41 def call() now = . return nil if @last_sent && (now - @last_sent) < @interval @last_sent = now @app.call() end |