class BBS::AI::Semaphore
A counting semaphore: at most a given number of holders at once, the others wait their turn for a while.
Public Class Methods
Source
# File lib/bbs/ai.rb, line 142 def initialize @mu = Mutex.new @freed = ConditionVariable.new @held = 0 end
Creates a semaphore nobody holds.
Public Instance Methods
# File lib/bbs/ai.rb, line 151 def hold(limit:, wait:) raise Busy, 'The model is busy, try again in a moment.' unless take(limit, wait) begin yield ensure give end end
Runs the block once fewer than limit hold the semaphore, waiting up to wait seconds for that. Returns the block’s value; raises Busy when the wait runs out.