123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Promises::FlatFuturePromise

Constant Summary

InternalStates - Included

PENDING, RESERVED, RESOLVED

Class Attribute Summary

Class Method Summary

AbstractFlatPromise - Inherited

BlockedPromise - Inherited

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 does.

.attr_volatile

Creates methods for reading and writing (as attr_accessor does) to a instance variable with volatile (Java) semantic.

.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 Attribute Summary

Instance Method Summary

Constructor Details

.new(delayed, blockers_count, levels, default_executor) ⇒ FlatFuturePromise (private)

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1877

def initialize(delayed, blockers_count, levels, default_executor)
  raise ArgumentError, 'levels has to be higher than 0' if levels < 1
  # flat promise may result to a future having delayed futures, therefore we have to have empty stack
  # to be able to add new delayed futures
  super delayed || LockFreeStack.new, 1 + levels, Future.new(self, default_executor)
end

Instance Method Details

#process_on_blocker_resolution(future, index) (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1884

def process_on_blocker_resolution(future, index)
  countdown = super(future, index)
  if countdown.nonzero?
    internal_state = future.internal_state

    unless internal_state.fulfilled?
      resolve_with internal_state
      return countdown
    end

    value = internal_state.value
    case value
    when AbstractEventFuture
      add_delayed_of value
      value.add_callback_notify_blocked self, nil
      countdown
    else
      evaluate_to(lambda { raise TypeError, "returned value #{value.inspect} is not a Future" })
    end
  end
  countdown
end