Class: Async::Limiter::Unlimited
- Inherits:
-
Object
- Object
- Async::Limiter::Unlimited
- Defined in:
- lib/async/limiter/unlimited.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #acquire ⇒ Object
- #async(parent: (@parent || Task.current), **options) ⇒ Object
- #blocking? ⇒ Boolean
-
#initialize(parent: nil) ⇒ Unlimited
constructor
A new instance of Unlimited.
- #limit ⇒ Object
- #release ⇒ Object
- #sync(*queue_args) ⇒ Object
Constructor Details
#initialize(parent: nil) ⇒ Unlimited
Returns a new instance of Unlimited.
8 9 10 11 |
# File 'lib/async/limiter/unlimited.rb', line 8 def initialize(parent: nil) @count = 0 @parent = parent end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
6 7 8 |
# File 'lib/async/limiter/unlimited.rb', line 6 def count @count end |
Instance Method Details
#acquire ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/async/limiter/unlimited.rb', line 36 def acquire @count += 1 return unless block_given? begin yield ensure release end end |
#async(parent: (@parent || Task.current), **options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/async/limiter/unlimited.rb', line 21 def async(parent: (@parent || Task.current), **) acquire parent.async(**) do |task| yield task ensure release end end |
#blocking? ⇒ Boolean
17 18 19 |
# File 'lib/async/limiter/unlimited.rb', line 17 def blocking? false end |
#limit ⇒ Object
13 14 15 |
# File 'lib/async/limiter/unlimited.rb', line 13 def limit Float::INFINITY end |
#release ⇒ Object
48 49 50 |
# File 'lib/async/limiter/unlimited.rb', line 48 def release @count -= 1 end |
#sync(*queue_args) ⇒ Object
30 31 32 33 34 |
# File 'lib/async/limiter/unlimited.rb', line 30 def sync(*queue_args) acquire(*queue_args) do yield(@parent || Task.current) end end |