Class: MutexMigrations::Semaphore

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mutex_migrations/semaphore.rb

Instance Method Summary collapse

Constructor Details

#initializeSemaphore

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

#callObject



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

#lockObject



19
20
21
# File 'lib/mutex_migrations/semaphore.rb', line 19

def lock
  @mutex.try_lock
end

#locked?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mutex_migrations/semaphore.rb', line 23

def locked?
  @mutex.locked?
end

#unlockObject



27
28
29
# File 'lib/mutex_migrations/semaphore.rb', line 27

def unlock
  @mutex.unlock
end