Class: Celluloid::Condition::Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition, task, mailbox, timeout) ⇒ Waiter

Returns a new instance of Waiter.


7
8
9
10
11
12
# File 'lib/celluloid/condition.rb', line 7

def initialize(condition, task, mailbox, timeout)
  @condition = condition
  @task = task
  @mailbox = mailbox
  @timeout = timeout
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition


13
14
15
# File 'lib/celluloid/condition.rb', line 13

def condition
  @condition
end

#taskObject (readonly)

Returns the value of attribute task


13
14
15
# File 'lib/celluloid/condition.rb', line 13

def task
  @task
end

Instance Method Details

#<<(message) ⇒ Object


15
16
17
# File 'lib/celluloid/condition.rb', line 15

def <<(message)
  @mailbox << message
end

#waitObject


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/celluloid/condition.rb', line 19

def wait
  begin
    message = @mailbox.receive(@timeout) do |msg|
      msg.is_a?(SignalConditionRequest) && msg.task == Thread.current
    end
  rescue TimeoutError
    raise ConditionError, "timeout after #{@timeout.inspect} seconds"
  end until message

  message.value
end