Class: Rbgo::Once
- Inherits:
-
Object
- Object
- Rbgo::Once
- Defined in:
- lib/rbgo/once.rb
Instance Method Summary collapse
- #do(&f) ⇒ Object
-
#initialize ⇒ Once
constructor
A new instance of Once.
Constructor Details
#initialize ⇒ Once
Returns a new instance of Once.
6 7 8 9 |
# File 'lib/rbgo/once.rb', line 6 def initialize self.mutex = Mutex.new self.called_flag = false end |
Instance Method Details
#do(&f) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbgo/once.rb', line 11 def do(&f) return nil if called_flag mutex.synchronize do unless called_flag begin f.call ensure self.called_flag = true end end end end |