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)

Create a new limiter with the specified capacity.

Signature

parameter limit Integer

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

returns Async::Limiter::Queued

A new limiter instance with pre-allocated tokens.

Implementation

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