Class: Semian::ThreadSafe::SlidingWindow
- Inherits:
-
Simple::SlidingWindow
- Object
- Simple::SlidingWindow
- Semian::ThreadSafe::SlidingWindow
- Defined in:
- lib/semian/simple_sliding_window.rb
Instance Attribute Summary
Attributes inherited from Simple::SlidingWindow
Instance Method Summary collapse
-
#initialize ⇒ SlidingWindow
constructor
A new instance of SlidingWindow.
- #push ⇒ Object
-
#reject! ⇒ Object
#size, #last, and #clear are not wrapped in a mutex.
Methods inherited from Simple::SlidingWindow
Constructor Details
#initialize ⇒ SlidingWindow
Returns a new instance of SlidingWindow.
49 50 51 52 |
# File 'lib/semian/simple_sliding_window.rb', line 49 def initialize(**) super @lock = Mutex.new end |
Instance Method Details
#push ⇒ Object
65 66 67 |
# File 'lib/semian/simple_sliding_window.rb', line 65 def push(*) @lock.synchronize { super } end |
#reject! ⇒ Object
#size, #last, and #clear are not wrapped in a mutex. For the first two, the worst-case is a thread-switch at a timing where they’d receive an out-of-date value–which could happen with a mutex as well.
As for clear, it’s an all or nothing operation. Doesn’t matter if we have the lock or not.
61 62 63 |
# File 'lib/semian/simple_sliding_window.rb', line 61 def reject!(*) @lock.synchronize { super } end |