Class: Demux::Demuxer

Inherits:
Object
  • Object
show all
Defined in:
lib/demux/demuxer.rb

Overview

Demux::Demuxer is the heart of pairing signals to apps. It's a base implementation of what needs to happen, but apps can provide their own custom demuxer that calls out to this one.

For example a host application will likely want to process signals in a background queue and can supply their own demuxer with details on how that should happen.

Instance Method Summary collapse

Constructor Details

#initialize(signal_attributes) ⇒ Demuxer

Returns a new instance of Demuxer.


12
13
14
15
16
# File 'lib/demux/demuxer.rb', line 12

def initialize(signal_attributes)
  @signal_attributes = signal_attributes
  @account_id = @signal_attributes.
  @signal_class = @signal_attributes.signal_class
end

Instance Method Details

#resolveself

Called by signal to resolve transmissions.

If you are implementing a custom demuxer, you can override this method to provide your own implementation as long as you ultimately call `#resolve_now` in your new implementation.

Returns:

  • (self)

26
27
28
29
30
# File 'lib/demux/demuxer.rb', line 26

def resolve
  resolve_now

  self
end

#resolve_nowself

Called by the implementation of #resolve to immediately resolve transmissions from a signal.

Returns:

  • (self)

37
38
39
40
41
42
43
44
45
# File 'lib/demux/demuxer.rb', line 37

def resolve_now
  queue_transmissions

  queued_transmissions.each do |transmission|
    transmit(transmission)
  end

  self
end

#transmit(transmission) ⇒ self

Called in `#resolve_now` when a resolved transmission is ready to be transmitted. You can override this in a custom demuxer as long as you ultimately call `#transmit` on the transmission.

Returns:

  • (self)

53
54
55
56
57
# File 'lib/demux/demuxer.rb', line 53

def transmit(transmission)
  transmission.transmit

  self
end