Class: MutexMigrations::Semaphore
- Inherits:
-
Object
- Object
- MutexMigrations::Semaphore
- Includes:
- Singleton
- Defined in:
- lib/mutex_migrations/semaphore.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ Semaphore
constructor
A new instance of Semaphore.
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Semaphore
Returns a new instance of Semaphore.
7 8 9 |
# File 'lib/mutex_migrations/semaphore.rb', line 7 def initialize @mutex = Mutex.new end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mutex_migrations/semaphore.rb', line 11 def call return unless block_given? @mutex.synchronize do yield end end |
#lock ⇒ Object
19 20 21 |
# File 'lib/mutex_migrations/semaphore.rb', line 19 def lock @mutex.try_lock end |
#locked? ⇒ Boolean
23 24 25 |
# File 'lib/mutex_migrations/semaphore.rb', line 23 def locked? @mutex.locked? end |
#unlock ⇒ Object
27 28 29 |
# File 'lib/mutex_migrations/semaphore.rb', line 27 def unlock @mutex.unlock end |