Sha256: 5c3cce39286c767247a25200b5b9650f81ee3ef3a55ce1f3ee47ad02b311f00b
Contents?: true
Size: 1.49 KB
Versions: 30
Compression:
Stored size: 1.49 KB
Contents
# module FaaStRuby # class ConcurrencyController # def self.store # @@store ||= {} # end # attr_accessor :params, :name, :max, :type # def initialize(name, max: 1, type:) # @type = type # @name = name # @max = max # @running = 0 # # @mutex = Mutex.new # self.class.store[name] = self # puts "(ConcurrencyController) Started controller for '#{name}' with max_concurrency = #{@max}".yellow # end # def running # # puts "[ConcurrencyController] [#{name}] Reading runners".red # # wait # # puts "[ConcurrencyController] [#{name}] Locking mutex".red # # @mutex.lock # @running # # ensure # # puts "[ConcurrencyController] [#{name}] Unlocking mutex".red # # @mutex.unlock # end # def decr(amount = 1) # incr(0 - amount) # end # def incr(amount = 1) # # puts "[ConcurrencyController] [#{name}] Incr #{amount}".red # # wait # # puts "[ConcurrencyController] [#{name}] Locking mutex".red # # @mutex.lock # current = @running + amount # return nil if max < current # @running += amount # # ensure # # puts "[ConcurrencyController] [#{name}] Unlocking mutex".red # # @mutex.unlock # end # # def wait # # puts "[ConcurrencyController] [#{name}] Waiting for mutex lock to release".red # # while @mutex.locked? do;end # # puts "[ConcurrencyController] [#{name}] Mutex released".red # # end # end # end
Version data entries
30 entries across 30 versions & 1 rubygems