Class: Goru::Channel
- Inherits:
-
Object
- Object
- Goru::Channel
- Defined in:
- lib/goru/channel.rb
Instance Attribute Summary collapse
-
#observer ⇒ Object
writeonly
[public].
Instance Method Summary collapse
-
#<<(message) ⇒ Object
[public].
-
#add_observer(observer) ⇒ Object
[public].
-
#any? ⇒ Boolean
[public].
-
#clear ⇒ Object
[public].
-
#close ⇒ Object
[public].
-
#closed? ⇒ Boolean
[public].
-
#empty? ⇒ Boolean
[public].
-
#full? ⇒ Boolean
[public].
-
#initialize(size: nil) ⇒ Channel
constructor
A new instance of Channel.
-
#length ⇒ Object
[public].
-
#read ⇒ Object
[public].
-
#remove_observer(observer) ⇒ Object
[public].
-
#reopen ⇒ Object
[public].
Constructor Details
#initialize(size: nil) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 11 12 |
# File 'lib/goru/channel.rb', line 7 def initialize(size: nil) @size = size = [] @closed = false @observers = Set.new end |
Instance Attribute Details
#observer=(value) ⇒ Object (writeonly)
- public
16 17 18 |
# File 'lib/goru/channel.rb', line 16 def observer=(value) @observer = value end |
Instance Method Details
#<<(message) ⇒ Object
- public
20 21 22 23 24 |
# File 'lib/goru/channel.rb', line 20 def <<() raise "closed" if @closed << @observers.each(&:channel_received) end |
#add_observer(observer) ⇒ Object
- public
86 87 88 |
# File 'lib/goru/channel.rb', line 86 def add_observer(observer) @observers << observer end |
#any? ⇒ Boolean
- public
36 37 38 |
# File 'lib/goru/channel.rb', line 36 def any? .any? end |
#clear ⇒ Object
- public
74 75 76 |
# File 'lib/goru/channel.rb', line 74 def clear .clear end |
#close ⇒ Object
- public
60 61 62 63 |
# File 'lib/goru/channel.rb', line 60 def close @closed = true @observers.each(&:channel_closed) end |
#closed? ⇒ Boolean
- public
54 55 56 |
# File 'lib/goru/channel.rb', line 54 def closed? @closed == true end |
#empty? ⇒ Boolean
- public
42 43 44 |
# File 'lib/goru/channel.rb', line 42 def empty? .empty? end |
#full? ⇒ Boolean
- public
48 49 50 |
# File 'lib/goru/channel.rb', line 48 def full? @size && .size == @size end |
#length ⇒ Object
- public
80 81 82 |
# File 'lib/goru/channel.rb', line 80 def length .length end |
#read ⇒ Object
- public
28 29 30 31 32 |
# File 'lib/goru/channel.rb', line 28 def read = .shift @observers.each(&:channel_read) end |
#remove_observer(observer) ⇒ Object
- public
92 93 94 |
# File 'lib/goru/channel.rb', line 92 def remove_observer(observer) @observers.delete(observer) end |
#reopen ⇒ Object
- public
67 68 69 70 |
# File 'lib/goru/channel.rb', line 67 def reopen @closed = false @observers.each(&:channel_reopened) end |