Skip to content

ssuljic/timed_semaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby TimedSemaphore

Description

A TimedSemaphore is a specialized implementation of a Semaphore that gives a number of permits in a given time frame. This gem is a Ruby implementation inspired by the Java implementation from the Apache Commons Lang package.

Installation

gem install timed_semaphore

Usage

Here is a basic example of using a TimedSemaphore:

require 'timed_semaphore'

threads = []
semaphore = TimedSemaphore.new(2, 3)

10.times do |x|
  threads << Thread.new do
    semaphore.acquire
    puts "Thread #{x}: " + Time.now.to_s
  end
end

threads.map(&:join)

Copyright

Please refer to LICENSE.

About

Ruby implementation of TimedSemaphore

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages