Module: Vigilem::Core::Eventable::ReadMethods Abstract
- Included in:
- Vigilem::Core::Eventable
- Defined in:
- lib/vigilem/core/eventable.rb
Overview
This module is abstract.
need to override read_many_nonblock, optional synchronize
Instance Method Summary collapse
-
#read_many(number_of_events = 1) ⇒ Array
reads until a specified number of events have been read.
- #read_many_nonblock(max_number_of_events = 1) ⇒ Array abstract
-
#read_one ⇒ Object
reads one Object and blocking if source is empty.
-
#read_one_nonblock ⇒ Object
reads one Object without blocking if source is empty.
-
#synchronize ⇒ Object
passes to super if exists, otherwise yield makes overwriting it optional.
Instance Method Details
#read_many(number_of_events = 1) ⇒ Array
reads until a specified number of events have been read
30 31 32 33 34 35 36 37 |
# File 'lib/vigilem/core/eventable.rb', line 30 def read_many(number_of_events=1) synchronize { until (events ||= []).size == number_of_events events += read_many_nonblock(number_of_events) end events } end |
#read_many_nonblock(max_number_of_events = 1) ⇒ Array
This method is abstract.
12 13 14 |
# File 'lib/vigilem/core/eventable.rb', line 12 def read_many_nonblock(max_number_of_events=1) raise NotImplemented, 'read_many_nonblock not overridden' end |
#read_one ⇒ Object
reads one Object and blocking if source is empty
49 50 51 52 53 |
# File 'lib/vigilem/core/eventable.rb', line 49 def read_one synchronize { read_many.slice!(0) } end |
#read_one_nonblock ⇒ Object
reads one Object without blocking if source is empty
41 42 43 44 45 |
# File 'lib/vigilem/core/eventable.rb', line 41 def read_one_nonblock synchronize { read_many_nonblock.slice!(0) } end |
#synchronize ⇒ Object
passes to super if exists, otherwise yield makes overwriting it optional
19 20 21 22 23 24 25 |
# File 'lib/vigilem/core/eventable.rb', line 19 def synchronize if defined?(super) super else yield end end |