Class: Bolt::PlanFuture
- Inherits:
-
Object
- Object
- Bolt::PlanFuture
- Defined in:
- lib/bolt/plan_future.rb
Instance Attribute Summary collapse
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(fiber, id, name = nil) ⇒ PlanFuture
constructor
A new instance of PlanFuture.
- #name ⇒ Object
- #raise(exception) ⇒ Object
- #resume ⇒ Object
- #state ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(fiber, id, name = nil) ⇒ PlanFuture
Returns a new instance of PlanFuture.
10 11 12 13 14 15 |
# File 'lib/bolt/plan_future.rb', line 10 def initialize(fiber, id, name = nil) @fiber = fiber @id = id @name = name @value = nil end |
Instance Attribute Details
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
7 8 9 |
# File 'lib/bolt/plan_future.rb', line 7 def fiber @fiber end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/bolt/plan_future.rb', line 7 def id @id end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/bolt/plan_future.rb', line 8 def value @value end |
Instance Method Details
#alive? ⇒ Boolean
25 26 27 |
# File 'lib/bolt/plan_future.rb', line 25 def alive? fiber.alive? end |
#name ⇒ Object
17 18 19 |
# File 'lib/bolt/plan_future.rb', line 17 def name @name || @id end |
#raise(exception) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bolt/plan_future.rb', line 29 def raise(exception) # Make sure the value gets set @value = exception # This was introduced in Ruby 2.7 begin # Raise an exception to kill the Fiber. If the Fiber has not been # resumed yet, or is already terminated this will raise a FiberError. # We don't especially care about the FiberError, as long as the Fiber # doesn't report itself as alive. fiber.raise(exception) rescue FiberError # If the Fiber is still alive, resume it with a block to raise the # exception which will terminate it. if fiber.alive? fiber.resume { raise(exception) } end end end |
#resume ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/bolt/plan_future.rb', line 48 def resume if fiber.alive? @value = fiber.resume else @value end end |
#state ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/bolt/plan_future.rb', line 56 def state if fiber.alive? "running" elsif value.is_a?(Exception) "error" else "done" end end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/bolt/plan_future.rb', line 21 def to_s "Future '#{name}'" end |