lib/concurrent/edge/throttle.rb in concurrent-ruby-edge-0.3.0 vs lib/concurrent/edge/throttle.rb in concurrent-ruby-edge-0.3.1
- old
+ new
@@ -8,10 +8,15 @@
# # Only 2 at the same time
# do_stuff
# end
# end
# end
+ # @!macro [new] throttle.example.throttled_future
+ # @example
+ # throttle.throttled_future(1) do |arg|
+ # arg.succ
+ # end
# @!macro [new] throttle.example.throttled_future_chain
# @example
# throttle.throttled_future_chain do |trigger|
# trigger.
# # 2 throttled promises
@@ -38,10 +43,11 @@
# futures.map(&:value!) # => [2, 3, 4, 5, nil]
# A tool manage concurrency level of future tasks.
#
# @!macro throttle.example.then_throttled_by
+ # @!macro throttle.example.throttled_future
# @!macro throttle.example.throttled_future_chain
# @!macro throttle.example.throttled_block
class Throttle < Synchronization::Object
# TODO (pitr-ch 21-Dec-2016): consider using sized channel for implementation instead when available
@@ -130,9 +136,10 @@
end
# Behaves as {Promises::FactoryMethods#future} but the future is throttled.
# @return [Promises::Future]
# @see Promises::FactoryMethods#future
+ # @!macro throttle.example.throttled_future
def throttled_future(*args, &task)
trigger.chain(*args, &task).on_resolution! { release }
end
end