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.



5
6
7
8
9
10
# File 'lib/celluloid/condition.rb', line 5

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.



11
12
13
# File 'lib/celluloid/condition.rb', line 11

def condition
  @condition
end

#taskObject (readonly)

Returns the value of attribute task.



11
12
13
# File 'lib/celluloid/condition.rb', line 11

def task
  @task
end

Instance Method Details

#<<(message) ⇒ Object



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

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

#waitObject



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

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

  message.value
end