Class: Async::Limiter::Unlimited

Inherits:
Object
  • Object
show all
Defined in:
lib/async/limiter/unlimited.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject (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

#acquireObject



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), **options)
  acquire
  parent.async(**options) do |task|
    yield task
  ensure
    release
  end
end

#blocking?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/async/limiter/unlimited.rb', line 17

def blocking?
  false
end

#limitObject



13
14
15
# File 'lib/async/limiter/unlimited.rb', line 13

def limit
  Float::INFINITY
end

#releaseObject



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