Module: MutexCode

Included in:
ContextR::ClassMethods
Defined in:
lib/contextr/modules/mutex_code.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#is_blocked?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/contextr/modules/mutex_code.rb', line 13

def is_blocked?
  semaphore.locked?
end

#only_onceObject



17
18
19
20
21
# File 'lib/contextr/modules/mutex_code.rb', line 17

def only_once
  synchronized do
    yield
  end unless is_blocked?
end

#semaphoreObject



3
4
5
# File 'lib/contextr/modules/mutex_code.rb', line 3

def semaphore
  @semaphore ||= Mutex.new
end

#synchronizedObject



7
8
9
10
11
# File 'lib/contextr/modules/mutex_code.rb', line 7

def synchronized
  semaphore.synchronize do
    yield
  end
end