Module: Concurrent::Promises::Resolvable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
InternalStates
|
|
Defined in: | lib/concurrent-ruby/concurrent/promises.rb, lib/concurrent-ruby-edge/concurrent/edge/promises.rb |
Overview
Constant Summary
InternalStates
- Included
Class Method Summary
-
.atomic_resolution(resolvable_map) ⇒ true, false
Resolves all passed events and futures to the given resolutions if possible (all are unresolved) or none.
- .locking_order_by(resolvable) ⇒ Comparable
Instance Method Summary
- #release ⇒ true, false
-
#reserve ⇒ true, false
Reserves the event or future, if reserved others are prevented from resolving it.
Class Method Details
.atomic_resolution(resolvable_map) ⇒ true
, false
Resolves all passed events and futures to the given resolutions if possible (all are unresolved) or none.
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 150
def self.atomic_resolution(resolvable_map) # atomic_resolution event => [], future => [true, :v, nil] sorted = resolvable_map.to_a.sort_by { |resolvable, _| locking_order_by resolvable } reserved = 0 while reserved < sorted.size && sorted[reserved].first.reserve reserved += 1 end if reserved == sorted.size sorted.each { |resolvable, args| resolvable.resolve(*args, true, true) } true else while reserved > 0 reserved -= 1 raise 'has to be reserved' unless sorted[reserved].first.release end false end end
.locking_order_by(resolvable) ⇒ Comparable
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 128
def self.locking_order_by(resolvable) resolvable.object_id end
Instance Method Details
#release ⇒ true
, false
#reserve ⇒ true
, false
Reserves the event or future, if reserved others are prevented from resolving it. Advanced feature. Be careful about the order of reservation to avoid deadlocks, the method blocks if the future or event is already reserved until it is released or resolved.