broadcaster 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ae6565dba10ebb367ec4454148293dd205c48cb
4
- data.tar.gz: fd6102f4293dc93488a2e0a82828b01fe294e821
3
+ metadata.gz: 9db2fe4bfde7c7696999349310f62e331fcf4bda
4
+ data.tar.gz: 36341eaf5595452ba33947f7144cefd6004372f7
5
5
  SHA512:
6
- metadata.gz: e6766995f6d199435b7dcb63aa0cf90d1633d89b61e7d72e3eb2d7e4f8f13ac30163800ae51e0e6db75a57cb0f0fd0204e44f82d9b06bfccb60e5c3e1aaf3ff0
7
- data.tar.gz: 8e875c87c94387862f724c57f41bcf7ade8156f117e3bade30680fed816ab7c8c29c44b8ab0d1eb910d0f1bd16551eac20e8deae32d7e477cf01effd8e9aa889
6
+ metadata.gz: 81c0b0bef9dd55b41082930634067078f166c7864d372a2bcf9b89baa9ec610232e9f2bc8cff4410e2260b7f62d1db6ecadb74a947834e67c8862dd6ae015ef8
7
+ data.tar.gz: c0abdbd7b65a60f070358959eec6772daf27f8fa29beeb58f7ea4208324108d8c1fcb05ca40b5578bd40f9152871ff040fd29087a2976862cc0924d2e549dbd9
data/broadcaster.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'broadcaster'
7
- spec.version = '0.1.0'
7
+ spec.version = '0.1.1'
8
8
  spec.authors = ['Gabriel Naiman']
9
9
  spec.email = ['gabynaiman@gmail.com']
10
10
  spec.summary = 'Broadcasting based on Redis PubSub'
data/lib/broadcaster.rb CHANGED
@@ -72,13 +72,11 @@ class Broadcaster
72
72
  channel = notification[2]
73
73
  message = Marshal.load notification[3]
74
74
  logger.debug(self.class) { "Broadcasting (#{subscriptions[channel].count}) | #{channel} | #{message}" }
75
- mutex.synchronize do
76
- subscriptions[channel].each do |subscription_id, block|
77
- begin
78
- block.call message
79
- rescue => ex
80
- logger.error(self.class) { "Failed | #{scoped(channel)} | #{subscription_id} | #{message}\n#{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}" }
81
- end
75
+ subscriptions[channel].each do |subscription_id, block|
76
+ begin
77
+ block.call message
78
+ rescue => ex
79
+ logger.error(self.class) { "Failed | #{channel} | #{subscription_id} | #{message}\n#{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}" }
82
80
  end
83
81
  end
84
82
  end
@@ -2,6 +2,18 @@ require 'minitest_helper'
2
2
 
3
3
  describe Broadcaster do
4
4
 
5
+ class Receiver
6
+ attr_reader :messages
7
+
8
+ def initialize
9
+ @messages = []
10
+ end
11
+
12
+ def call(message)
13
+ messages << message
14
+ end
15
+ end
16
+
5
17
  def wait_for(&block)
6
18
  Timeout.timeout(3) do
7
19
  while !block.call
@@ -142,4 +154,20 @@ describe Broadcaster do
142
154
  error.message.must_match 'invalid_host'
143
155
  end
144
156
 
157
+ it 'Subscribe object' do
158
+ broadcaster = Broadcaster.new
159
+
160
+ receiver = Receiver.new
161
+
162
+ broadcaster.subscribe 'channel_1', receiver
163
+
164
+ broadcaster.publish 'channel_1', 'message 1'
165
+ broadcaster.publish 'channel_1', 'message 2'
166
+ broadcaster.publish 'channel_1', 'message 3'
167
+
168
+ wait_for { receiver.messages.count == 3 }
169
+
170
+ receiver.messages.must_equal ['message 1', 'message 2', 'message 3']
171
+ end
172
+
145
173
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: broadcaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redic