123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Promises::AbstractFlatPromise

Constant Summary

InternalStates - Included

PENDING, RESERVED, RESOLVED

Class Attribute Summary

Class Method Summary

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_because, blockers_count, event_or_future) ⇒ AbstractFlatPromise

[ GitHub ]

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

def initialize(delayed_because, blockers_count, event_or_future)
  delayed = LockFreeStack.of1(self)
  super(delayed, blockers_count, event_or_future)
  # noinspection RubyArgCount
  @Touched        = AtomicBoolean.new false
  @DelayedBecause = delayed_because || LockFreeStack.new

  event_or_future.add_callback_clear_delayed_node delayed.peek
end

Instance Attribute Details

#touched?Boolean (readonly, private)

[ GitHub ]

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

def touched?
  @Touched.value
end

Instance Method Details

#add_delayed_of(future) (private)

[ GitHub ]

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

def add_delayed_of(future)
  delayed = future.promise.delayed_because
  if touched?
    clear_and_propagate_touch delayed
  else
    BlockedPromise.add_delayed @DelayedBecause, delayed
    clear_and_propagate_touch @DelayedBecause if touched?
  end
end

#on_resolvable(resolved_future, index) (private)

[ GitHub ]

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

def on_resolvable(resolved_future, index)
  resolve_with resolved_future.internal_state
end

#resolvable?(countdown, future, index) ⇒ Boolean (private)

[ GitHub ]

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

def resolvable?(countdown, future, index)
  !@Future.internal_state.resolved? && super(countdown, future, index)
end

#touch

[ GitHub ]

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

def touch
  if @Touched.make_true
    clear_and_propagate_touch @DelayedBecause
  end
end