Module: Concurrent::Promises::FactoryMethods

Included in:
Throttle
Defined in:
lib/concurrent-ruby-edge/concurrent/edge/promises.rb,
lib/concurrent-ruby-edge/concurrent/edge/old_channel_integration.rb

Instance Method Summary collapse

Instance Method Details

#zip_futures_over(enumerable, &future_factory) ⇒ Future

Returns:



72
73
74
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 72

def zip_futures_over(enumerable, &future_factory)
  zip_futures_over_on default_executor, enumerable, &future_factory
end

#zip_futures_over_on(default_executor, enumerable) {|element| ... } ⇒ Future

Creates new future which is resolved after all the futures created by future_factory from enumerable elements are resolved. Simplified it does: ‘zip(*enumerable.map { |e| future e, &future_factory })`

Examples:

# `#succ` calls are executed in parallel
zip_futures_over_on(:io, [1, 2], &:succ).value! # => [2, 3]

Parameters:

  • enumerable (Enumerable)

Yields:

  • a task to be executed in future

Yield Parameters:

  • element (Object)

    from enumerable

Yield Returns:

  • (Object)

    a value of the future

Returns:



90
91
92
93
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 90

def zip_futures_over_on(default_executor, enumerable, &future_factory)
  # ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future
  zip_futures_on(default_executor, *enumerable.map { |e| future e, &future_factory })
end