Class: Concurrent::Promises::BlockedPromise Abstract
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
AbstractAnyPromise, AbstractFlatPromise, AnyFulfilledFuturePromise, AnyResolvedEventPromise, AnyResolvedFuturePromise, BlockedTaskPromise, ChainPromise, EventWrapperPromise, FlatEventPromise, FlatFuturePromise, FutureWrapperPromise, RescuePromise, RunFuturePromise, ThenPromise, ZipEventEventPromise, ZipEventsPromise, ZipFutureEventPromise, ZipFuturesPromise
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Promises::InnerPromise
|
Defined in: | lib/concurrent-ruby/concurrent/promises.rb |
Overview
This class is abstract.
Constant Summary
InternalStates
- Included
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
- .add_delayed(delayed1, delayed2)
- .new(delayed, blockers_count, future) ⇒ BlockedPromise constructor
- .new_blocked_by(blockers, *args, &block)
- .new_blocked_by1(blocker, *args, &block)
- .new_blocked_by2(blocker1, blocker2, *args, &block)
AbstractPromise
- Inherited
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Method Summary
-
#blocked_by
for inspection only.
- #delayed_because
- #on_blocker_resolution(future, index)
- #touch
- #clear_and_propagate_touch(stack_or_element = @Delayed) private
- #on_resolvable(resolved_future, index) private
- #process_on_blocker_resolution(future, index) private
- #resolvable?(countdown, future, index) ⇒ true, false private
AbstractPromise
- Inherited
#default_executor, #delayed_because, | |
#event | Alias for AbstractPromise#future. |
#future, | |
#inspect | Alias for AbstractPromise#to_s. |
#state, #to_s, #touch, #evaluate_to, #resolve_with |
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
.new(delayed, blockers_count, future) ⇒ BlockedPromise
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1661
def initialize(delayed, blockers_count, future) super(future) @Delayed = delayed @Countdown = AtomicFixnum.new blockers_count end
Class Method Details
.add_delayed(delayed1, delayed2)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1652
def self.add_delayed(delayed1, delayed2) if delayed1 && delayed2 delayed1.push delayed2 delayed1 else delayed1 || delayed2 end end
.new_blocked_by(blockers, *args, &block)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1645
def self.new_blocked_by(blockers, *args, &block) delayed = blockers.reduce(nil) { |d, f| add_delayed d, f.promise.delayed_because } promise = new(delayed, blockers.size, *args, &block) blockers.each_with_index { |f, i| f.add_callback_notify_blocked promise, i } promise end
.new_blocked_by1(blocker, *args, &block)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1623
def self.new_blocked_by1(blocker, *args, &block) blocker_delayed = blocker.promise.delayed_because promise = new(blocker_delayed, 1, *args, &block) blocker.add_callback_notify_blocked promise, 0 promise end
.new_blocked_by2(blocker1, blocker2, *args, &block)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1630
def self.new_blocked_by2(blocker1, blocker2, *args, &block) blocker_delayed1 = blocker1.promise.delayed_because blocker_delayed2 = blocker2.promise.delayed_because delayed = if blocker_delayed1 && blocker_delayed2 # TODO (pitr-ch 23-Dec-2016): use arrays when we know it will not grow (only flat adds delay) LockFreeStack.of2(blocker_delayed1, blocker_delayed2) else blocker_delayed1 || blocker_delayed2 end promise = new(delayed, 2, *args, &block) blocker1.add_callback_notify_blocked promise, 0 blocker2.add_callback_notify_blocked promise, 1 promise end
Instance Method Details
#blocked_by
for inspection only
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1683
def blocked_by blocked_by = [] ObjectSpace.each_object(AbstractEventFuture) { |o| blocked_by.push o if o.blocks.include? self } blocked_by end
#clear_and_propagate_touch(stack_or_element = @Delayed) (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1691
def clear_and_propagate_touch(stack_or_element = @Delayed) return if stack_or_element.nil? if stack_or_element.is_a? LockFreeStack stack_or_element.clear_each { |element| clear_and_propagate_touch element } else stack_or_element.touch unless stack_or_element.nil? # if still present end end
#delayed_because
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1674
def delayed_because @Delayed end
#on_blocker_resolution(future, index)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1667
def on_blocker_resolution(future, index) countdown = process_on_blocker_resolution(future, index) resolvable = resolvable?(countdown, future, index) on_resolvable(future, index) if resolvable end
#on_resolvable(resolved_future, index) (private)
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1710
def on_resolvable(resolved_future, index) raise NotImplementedError end
#process_on_blocker_resolution(future, index) (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1706
def process_on_blocker_resolution(future, index) @Countdown.decrement end
#resolvable?(countdown, future, index) ⇒ true
, false
(private)
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1702
def resolvable?(countdown, future, index) countdown.zero? end
#touch
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1678
def touch clear_and_propagate_touch end