Class: Reqless::ClientEvents
- Inherits:
-
Object
- Object
- Reqless::ClientEvents
- Defined in:
- lib/reqless.rb
Overview
A class for interacting with events. Not meant to be instantiated directly, it’s accessed through Client#events
Constant Summary collapse
- EVENTS =
%w{canceled completed failed popped stalled put track untrack}
Instance Method Summary collapse
-
#initialize(redis) ⇒ ClientEvents
constructor
A new instance of ClientEvents.
- #listen {|_self| ... } ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(redis) ⇒ ClientEvents
Returns a new instance of ClientEvents.
203 204 205 206 |
# File 'lib/reqless.rb', line 203 def initialize(redis) @redis = redis @actions = {} end |
Instance Method Details
#listen {|_self| ... } ⇒ Object
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/reqless.rb', line 208 def listen yield(self) if block_given? channels = EVENTS.map { |event| "ql:#{event}" } @redis.subscribe(channels) do |on| on. do |channel, | callback = @actions[channel.sub('ql:', '').to_sym] callback.call() unless callback.nil? end end end |
#stop ⇒ Object
219 220 221 |
# File 'lib/reqless.rb', line 219 def stop @redis.unsubscribe end |