Class List Method List File List

# Module: Concurrent::Throttle::PromisesIntegration

Included in:
  Concurrent::Throttle
Defined in:
  lib/concurrent/edge/throttle.rb

## Instance Method Summary (collapse)

- - (Promises::Future) throttled_future(*args, &task)

  Behaves as Promises::FactoryMethods#future but the future is throttled.

- - (Promises::Event, Promises::Future) throttled_future_chain {|trigger| ... }

  Allows to throttle a chain of promises.

## Instance Method Details

### - (`Promises::Future`) throttled_future(*args, &task)

Behaves as Promises::FactoryMethods#future but the future is throttled.

Examples:

    throttle.throttled_future(1) do |arg|
      arg.succ
    end

Returns:

- (`Promises::Future`)

See Also:

- Promises::FactoryMethods#future

    142
    143
    144

    # File 'lib/concurrent/edge/throttle.rb', line 142

    def throttled_future(*args, &task)
      trigger.chain(*args, &task).on_resolution! { release }
    end

### - (`Promises::Event`, `Promises::Future`) throttled_future_chain {|trigger| ... }

Allows to throttle a chain of promises.

Examples:

    throttle.throttled_future_chain do |trigger|
      trigger.
          # 2 throttled promises
          chain { 1 }.
          then(&:succ)
    end

Yields:

- (`trigger`) —

  a trigger which has to be used to build up a chain of promises, the last one is result of the block. When the last one resolves, Concurrent::Throttle#release is called on the throttle.

Yield Parameters:

- trigger (`Promises::Event`, `Promises::Future`)

Yield Returns:

- (`Promises::Event`, `Promises::Future`) —

  The final future of the throttled chain.

Returns:

- (`Promises::Event`, `Promises::Future`) —

  The final future of the throttled chain.

    134
    135
    136

    # File 'lib/concurrent/edge/throttle.rb', line 134

    def throttled_future_chain(&throttled_futures)
      throttled_futures.call(trigger).on_resolution! { release }
    end