Class: Apnotic::Stream
- Inherits:
-
Object
- Object
- Apnotic::Stream
- Defined in:
- lib/apnotic/stream.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Stream
constructor
A new instance of Stream.
- #push(notification, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Stream
Returns a new instance of Stream.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/apnotic/stream.rb', line 7 def initialize(={}) @h2_stream = [:h2_stream] @uri = [:uri] @headers = {} @data = '' @completed = false @mutex = Mutex.new @cv = ConditionVariable.new @h2_stream.on(:headers) do |hs| hs.each { |k, v| @headers[k] = v } end @h2_stream.on(:data) { |d| @data << d } @h2_stream.on(:close) do @mutex.synchronize do @completed = true @cv.signal end end end |
Instance Method Details
#push(notification, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/apnotic/stream.rb', line 29 def push(notification, ={}) headers = build_headers_for notification body = notification.body @h2_stream.headers(headers, end_stream: false) @h2_stream.data(body, end_stream: true) respond() end |