Class: Async::Limiter::Timing::Ordered

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

Overview

Ordered timing strategy wrapper that preserves FIFO ordering.

This wrapper delegates to any timing strategy but ensures that tasks acquire capacity in the order they requested it, preventing starvation of high-cost operations by continuous low-cost operations.

Instance Method Summary collapse

Constructor Details

#initialize(delegate) ⇒ Ordered

Initialize ordered timing wrapper.



20
21
22
23
# File 'lib/async/limiter/timing/ordered.rb', line 20

def initialize(delegate)
	@delegate = delegate
	@mutex = Mutex.new
end

Instance Method Details

#acquire(cost = 1) ⇒ Object

Record acquisition in delegate strategy.



33
34
35
# File 'lib/async/limiter/timing/ordered.rb', line 33

def acquire(cost = 1)
	@delegate.acquire(cost)
end

#maximum_costObject

Get maximum cost from delegate strategy.



27
28
29
# File 'lib/async/limiter/timing/ordered.rb', line 27

def maximum_cost
	@delegate.maximum_cost
end

#statisticsObject

Get current timing strategy statistics from delegate.



50
51
52
53
54
# File 'lib/async/limiter/timing/ordered.rb', line 50

def statistics
	@delegate.statistics.tap do |statistics|
		statistics[:ordered] = true
	end
end

#wait(mutex, deadline = nil, cost = 1) ⇒ Object

Wait with FIFO ordering preserved.



42
43
44
45
46
# File 'lib/async/limiter/timing/ordered.rb', line 42

def wait(mutex, deadline = nil, cost = 1)
	@mutex.synchronize do
		@delegate.wait(mutex, deadline, cost)
	end
end