Class: Obuf::ProtectedLens

Inherits:
Lens
  • Object
show all
Defined in:
lib/obuf/protected_lens.rb

Overview

Similar to Obuf::Lens but protects all the operations that change the IO offset with a Mutex.

Constant Summary

Constants inherited from Lens

Lens::DELIM, Lens::END_RECORD, Lens::NothingToRecover

Instance Method Summary collapse

Methods inherited from Lens

#each

Constructor Details

#initialize(io) ⇒ ProtectedLens

Returns a new instance of ProtectedLens.



6
7
8
9
# File 'lib/obuf/protected_lens.rb', line 6

def initialize(io)
  super
  @mutex = Mutex.new
end

Instance Method Details

#<<(object_to_store) ⇒ Object

Store an object



12
13
14
# File 'lib/obuf/protected_lens.rb', line 12

def <<(object_to_store)
  @mutex.synchronize { super }
end

#recover_at(idx) ⇒ Object



16
17
18
# File 'lib/obuf/protected_lens.rb', line 16

def recover_at(idx)
  @mutex.synchronize { super }
end

#recover_objectObject



20
21
22
# File 'lib/obuf/protected_lens.rb', line 20

def recover_object
  @mutex.synchronize { super }
end