Class: Burg::Once

Inherits:
Object
  • Object
show all
Defined in:
lib/burg/once.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Once

Returns a new instance of Once.



3
4
5
6
# File 'lib/burg/once.rb', line 3

def initialize(&block)
  @block = block
  @mutex = Mutex.new
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
# File 'lib/burg/once.rb', line 8

def call
  @mutex&.synchronize do
    return unless @mutex

    @block.call

    @mutex = nil
  end
end