Class: Ori::Broadcast::Subscription

Inherits:
Object
  • Object
show all
Includes:
Selectable
Defined in:
lib/ori/broadcast.rb

Overview

: [E]

Instance Method Summary collapse

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

#awaitObject

: () -> Subscription



56
57
58
59
# File 'lib/ori/broadcast.rb', line 56

def await
  peek
  self
end

#deconstructObject

: () -> Array



62
63
64
65
# File 'lib/ori/broadcast.rb', line 62

def deconstruct
  Ori.sync { peek }
  [take]
end

#peekObject

: () -> E



45
46
47
48
# File 'lib/ori/broadcast.rb', line 45

def peek
  Fiber.yield(self) until value?
  @queue.first #: as E
end

#takeObject

: () -> E



39
40
41
42
# File 'lib/ori/broadcast.rb', line 39

def take
  Fiber.yield(self) until value?
  @queue.shift #: as E
end

#unsubscribeObject

: () -> void



68
69
70
# File 'lib/ori/broadcast.rb', line 68

def unsubscribe
  @broadcast.unsubscribe(self)
end

#value?Boolean

: () -> bool

Returns:

  • (Boolean)


51
52
53
# File 'lib/ori/broadcast.rb', line 51

def value?
  !@queue.empty?
end