Class: IncreasingMicrosecondClock
- Inherits:
-
Object
- Object
- IncreasingMicrosecondClock
- Defined in:
- lib/increasing_microsecond_clock.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(timestamp_factory = lambda { Time.stamp }, mutex = Mutex.new) ⇒ IncreasingMicrosecondClock
constructor
A new instance of IncreasingMicrosecondClock.
Constructor Details
#initialize(timestamp_factory = lambda { Time.stamp }, mutex = Mutex.new) ⇒ IncreasingMicrosecondClock
Returns a new instance of IncreasingMicrosecondClock.
4 5 6 7 8 9 |
# File 'lib/increasing_microsecond_clock.rb', line 4 def initialize( = lambda { Time.stamp }, mutex = Mutex.new) @timestamp_factory = @mutex = mutex @time = @timestamp_factory.call end |
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
27 28 29 |
# File 'lib/increasing_microsecond_clock.rb', line 27 def instance @instance end |
Class Method Details
.call ⇒ Object
29 30 31 |
# File 'lib/increasing_microsecond_clock.rb', line 29 def call instance.call end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/increasing_microsecond_clock.rb', line 11 def call @mutex.synchronize { new_time = @timestamp_factory.call @time = if new_time > @time new_time else @time + 1 end } end |