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.
47 48 49 50 |
# File 'lib/semian/simple_sliding_window.rb', line 47 def initialize(**) super @lock = Mutex.new end |
Instance Method Details
#push ⇒ Object
63 64 65 |
# File 'lib/semian/simple_sliding_window.rb', line 63 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.
59 60 61 |
# File 'lib/semian/simple_sliding_window.rb', line 59 def reject!(*) @lock.synchronize { super } end |