Class: Ori::Broadcast::Subscription
- Inherits:
-
Object
- Object
- Ori::Broadcast::Subscription
- Includes:
- Selectable
- Defined in:
- lib/ori/broadcast.rb
Overview
: [E]
Instance Method Summary collapse
-
#__send_item(item) ⇒ Object
private
: (E item) -> void.
-
#await ⇒ Object
: () -> Subscription.
-
#deconstruct ⇒ Object
: () -> Array.
-
#initialize(broadcast) ⇒ Subscription
constructor
: (Broadcast broadcast) -> void.
-
#peek ⇒ Object
: () -> E.
-
#take ⇒ Object
: () -> E.
-
#unsubscribe ⇒ Object
: () -> void.
-
#value? ⇒ Boolean
: () -> bool.
Constructor Details
#initialize(broadcast) ⇒ Subscription
: (Broadcast broadcast) -> void
33 34 35 36 |
# File 'lib/ori/broadcast.rb', line 33 def initialize(broadcast) @broadcast = broadcast @queue = [] #: Array[E] end |
Instance Method Details
#__send_item(item) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
: (E item) -> void
74 75 76 |
# File 'lib/ori/broadcast.rb', line 74 def __send_item(item) @queue << item end |
#await ⇒ Object
: () -> Subscription
56 57 58 59 |
# File 'lib/ori/broadcast.rb', line 56 def await peek self end |
#deconstruct ⇒ Object
: () -> Array
62 63 64 65 |
# File 'lib/ori/broadcast.rb', line 62 def deconstruct Ori.sync { peek } [take] end |
#peek ⇒ Object
: () -> E
45 46 47 48 |
# File 'lib/ori/broadcast.rb', line 45 def peek Fiber.yield(self) until value? @queue.first #: as E end |
#take ⇒ Object
: () -> E
39 40 41 42 |
# File 'lib/ori/broadcast.rb', line 39 def take Fiber.yield(self) until value? @queue.shift #: as E end |
#unsubscribe ⇒ Object
: () -> void
68 69 70 |
# File 'lib/ori/broadcast.rb', line 68 def unsubscribe @broadcast.unsubscribe(self) end |
#value? ⇒ Boolean
: () -> bool
51 52 53 |
# File 'lib/ori/broadcast.rb', line 51 def value? !@queue.empty? end |