Class: Tribe::SafeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/tribe/safe_set.rb

Instance Method Summary collapse

Constructor Details

#initializeSafeSet

Returns a new instance of SafeSet.



7
8
9
10
11
12
# File 'lib/tribe/safe_set.rb', line 7

def initialize
  @mutex = Mutex.new
  @set = Set.new

  return nil
end

Instance Method Details

#add(item) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tribe/safe_set.rb', line 14

def add(item)
  @mutex.synchronize do
    @set.add(item)
  end

  return self
end

#delete(item) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/tribe/safe_set.rb', line 22

def delete(item)
  @mutex.synchronize do
    @set.delete(item)
  end

  return self
end

#each(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/tribe/safe_set.rb', line 30

def each(&block)
  @mutex.synchronize do
    @set.each do |item|
      yield(item)
    end
  end

  return self
end