Module: Concurrent::Throttle::PromisesIntegration — Concurrent Ruby

# Module: Concurrent::Throttle::PromisesIntegration

Included in:
  Concurrent::Throttle

Defined in:
  lib-edge/concurrent/edge/throttle.rb

## Instance Method Summary collapse

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

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

- #throttled_future_chain {|trigger| ... } ⇒ Promises::Event, Promises::Future

  Allows to throttle a chain of promises.

## Instance Method Details

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

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

    145
    146
    147
    # File 'lib-edge/concurrent/edge/throttle.rb', line 145

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

### #throttled_future_chain {|trigger| ... } ⇒ `Promises::Event`, `Promises::Future`

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.

    137
    138
    139
    # File 'lib-edge/concurrent/edge/throttle.rb', line 137

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