Class: Ciri::DevP2P::Actor::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/devp2p/actor.rb

Overview

future, use this to wait actor msg respond

Instance Method Summary collapse

Constructor Details

#initializeFuture

Returns a new instance of Future.


62
63
64
65
# File 'lib/ciri/devp2p/actor.rb', line 62

def initialize
  @value = nil
  @done = false
end

Instance Method Details

#raise_error(error) ⇒ Object


88
89
90
91
92
# File 'lib/ciri/devp2p/actor.rb', line 88

def raise_error(error)
  error.set_backtrace(caller) if error.backtrace.nil?
  @error = error
  @queue << :error if @queue
end

#valueObject


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ciri/devp2p/actor.rb', line 76

def value
  loop do
    if @done
      return @value
    elsif @error
      raise @error
    else
      queue.pop
    end
  end
end

#value=(val) ⇒ Object


67
68
69
70
71
72
73
74
# File 'lib/ciri/devp2p/actor.rb', line 67

def value=(val)
  if @done
    raise RuntimeError.new('future value duplicated set')
  end
  @done = true
  @queue << :done if @queue
  @value = val
end