Falcon LimiterSourceFalconLimiterSemaphore

module Semaphore

Simple wrapper around Async::Limiter::Queued that provides the interface expected by Falcon while leveraging async-limiter's implementation.

Definitions

def self.new(limit = 1, **options)

Create a new limiter with the specified capacity.

Signature

parameter limit Integer

The maximum number of concurrent operations allowed (default: 1).

parameter options Hash

Options passed to Async::Limiter::Queued#initialize.

returns Async::Limiter::Queued

A new limiter instance with pre-allocated tokens.

Implementation

def self.new(limit = 1, **options)
	# Create priority queue and pre-populate with tokens
	queue = Async::PriorityQueue.new
	limit.times{queue.push(true)}
	
	return Async::Limiter::Queued.new(queue, **options)
end