Class: ThreadSafeHash

Inherits:
CaseInsensitiveHash show all
Defined in:
lib/failirc/extensions.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ThreadSafeHash

Returns a new instance of ThreadSafeHash.



81
82
83
84
85
# File 'lib/failirc/extensions.rb', line 81

def initialize (*args)
    @semaphore = Mutex.new

    super(*args)
end

Instance Method Details

#[](key) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/failirc/extensions.rb', line 105

def [] (key)
    begin
        @semaphore.synchronize {
            return __get__(key)
        }
    rescue ThreadError
        return __get__(key)
    end
end

#[]=(key, value) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/failirc/extensions.rb', line 95

def []= (key, value)
    begin
        @semaphore.synchronize {
            return __set__(key, value)
        }
    rescue ThreadError
        return __set__(key, value)
    end
end

#delete(key) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/failirc/extensions.rb', line 115

def delete (key)
    begin
        @semaphore.synchronize {
            return __delete__(key)
        }
    rescue ThreadError
        return __delete__(key)
    end
end