attention 0.0.4 → 0.0.5

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: a8af4c7faf9eb54ba645edb877ff536a7fafa8bf
4
- data.tar.gz: f86a41e076ea6fe24b75fb77f97c34f811c482ac
3
+ metadata.gz: d854a64d0631d2acc718ee5d310ee1e492e2e2cf
4
+ data.tar.gz: c4403ff3290f181ff6f1f7f5fd63225ee54def8b
5
5
  SHA512:
6
- metadata.gz: 85d5fd4a5226c7c07ee4ce21446a0e4b27a66dacd8b4a81f919f3b60130e13ea112fd925592d3be79b3a0cf9b54ea8ac20c5fd2814635b1e8ebe4a46abf672d1
7
- data.tar.gz: b2df4bd64a4d23abed0c155f7c3bc6592b39e56be535bb1263f11fba10b84619e5f448b42a4b4df06f3aed2a4cc2d87b40661092eebf556e0e562a733fd06549
6
+ metadata.gz: 91daaa57e01146e683e8fba37fd3c94c5b1a868ef7602f5aacbdf2ab57397ffd9c1a2f66caab2fc0d4f6d966d45467f55d4c35956e4ccfb3c97c503bc9497fcc
7
+ data.tar.gz: dd233e7e2ee479f9f87d0cc361de3c0f4d5fb9865970dfb7668460e42d80f970e35450a1c5aca0823d87995bdda8ef29cbba33ed3d72f88dc73a80c4d921d59d
data/lib/attention.rb CHANGED
@@ -2,6 +2,7 @@ require 'redis'
2
2
  require 'attention/version'
3
3
  require 'attention/redis_pool'
4
4
  require 'attention/subscriber'
5
+ require 'attention/blocking_subscriber'
5
6
  require 'attention/instance'
6
7
  require 'attention/timer'
7
8
 
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+ require 'attention/connection'
3
+ require 'attention/publisher'
4
+
5
+ module Attention
6
+ # Uses Redis pub/sub to synchronously respond to events
7
+ #
8
+ # Each Subscriber uses a Redis connection to listen to a channel for events.
9
+ class BlockingSubscriber
10
+ # The channel subscribed to
11
+ attr_reader :channel
12
+
13
+ # @!visibility private
14
+ attr_reader :redis
15
+
16
+ # Creates a subscription to the given channel
17
+ # @param channel [String] The channel to listen to
18
+ # @yield The code to execute on a published event
19
+ # @yieldparam channel [String] The channel the subscriber is listening to
20
+ # @yieldparam data [Object] The event published on the channel
21
+ # @yieldparam subscriber [BlockingSubscriber] This instance
22
+ def initialize(channel, &callback)
23
+ @channel = channel
24
+ @redis = Connection.new
25
+ subscribe &callback
26
+ end
27
+
28
+ # Sets up the Redis pub/sub subscription
29
+ # @yield The code to execute on a published event
30
+ def subscribe(&callback)
31
+ redis.subscribe(channel) do |on|
32
+ on.message do |channel, payload|
33
+ data = JSON.parse(payload) rescue payload
34
+ callback.call channel, data, self
35
+ end
36
+ end
37
+ end
38
+
39
+ # The {Publisher} used to send the unsubscribe message
40
+ # @api private
41
+ def publisher
42
+ @publisher ||= Publisher.new
43
+ end
44
+
45
+ # Unsubscribes from the channel
46
+ def unsubscribe
47
+ redis.unsubscribe
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Attention
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attention
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -185,6 +185,7 @@ files:
185
185
  - bin/setup
186
186
  - examples/awareness.rb
187
187
  - lib/attention.rb
188
+ - lib/attention/blocking_subscriber.rb
188
189
  - lib/attention/connection.rb
189
190
  - lib/attention/instance.rb
190
191
  - lib/attention/publisher.rb