Class: ProtonBot::EventLock

Inherits:
Object
  • Object
show all
Defined in:
lib/protonbot/event_lock.rb

Overview

Event lock. Locks current thread until matching event is emitted

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plug, pattern) ⇒ EventLock

Returns a new instance of EventLock.

Parameters:

  • plug (Plug)
  • pattern (Hash<Symbol>)


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

#patternHash<Symbol> (readonly)

Returns Pattern.

Returns:

  • (Hash<Symbol>)

    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

#plugPlug (readonly)

Returns Plug.

Returns:



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

#unlockNilClass

Unlocks current thread

Returns:

  • (NilClass)


21
22
23
24
# File 'lib/protonbot/event_lock.rb', line 21

def unlock
  @unlock = true
  nil
end