Class: ProtonBot::EventLock
- Inherits:
-
Object
- Object
- ProtonBot::EventLock
- Defined in:
- lib/protonbot/event_lock.rb
Overview
Event lock. Locks current thread until matching event is emitted
Instance Attribute Summary collapse
-
#pattern ⇒ Hash<Symbol>
readonly
Pattern.
-
#plug ⇒ Plug
readonly
Plug.
Instance Method Summary collapse
-
#initialize(plug, pattern) ⇒ EventLock
constructor
A new instance of EventLock.
-
#unlock ⇒ NilClass
Unlocks current thread.
Constructor Details
#initialize(plug, pattern) ⇒ EventLock
Returns a new instance of EventLock.
11 12 13 14 15 16 17 |
# File 'lib/protonbot/event_lock.rb', line 11 def initialize(plug, pattern) @plug = plug @plug.event_locks << self @pattern = pattern @unlock = false sleep(0.01) until @unlock end |
Instance Attribute Details
#pattern ⇒ Hash<Symbol> (readonly)
Returns Pattern.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/protonbot/event_lock.rb', line 6 class ProtonBot::EventLock attr_reader :plug, :pattern # @param plug [Plug] # @param pattern [Hash<Symbol>] def initialize(plug, pattern) @plug = plug @plug.event_locks << self @pattern = pattern @unlock = false sleep(0.01) until @unlock end # Unlocks current thread # @return [NilClass] def unlock @unlock = true nil end end |
#plug ⇒ Plug (readonly)
Returns Plug.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/protonbot/event_lock.rb', line 6 class ProtonBot::EventLock attr_reader :plug, :pattern # @param plug [Plug] # @param pattern [Hash<Symbol>] def initialize(plug, pattern) @plug = plug @plug.event_locks << self @pattern = pattern @unlock = false sleep(0.01) until @unlock end # Unlocks current thread # @return [NilClass] def unlock @unlock = true nil end end |
Instance Method Details
#unlock ⇒ NilClass
Unlocks current thread
21 22 23 24 |
# File 'lib/protonbot/event_lock.rb', line 21 def unlock @unlock = true nil end |