Class: Agent::Once
- Inherits:
-
Object
- Object
- Agent::Once
- Defined in:
- lib/agent/once.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Once
constructor
A new instance of Once.
- #perform ⇒ Object
- #performed? ⇒ Boolean
Constructor Details
#initialize ⇒ Once
Returns a new instance of Once.
3 4 5 6 |
# File 'lib/agent/once.rb', line 3 def initialize @mutex = Mutex.new @performed = false end |
Instance Method Details
#perform ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/agent/once.rb', line 8 def perform # optimium path return nil, error if @performed # slow path @mutex.synchronize do return nil, error if @performed @performed = true end return yield, nil end |
#performed? ⇒ Boolean
21 22 23 |
# File 'lib/agent/once.rb', line 21 def performed? @performed end |