tiny_bus 3.8.1 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tiny_bus.rb +19 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b1e1dbd8b946c901082f84c21d979003b6d69f1d41a7e1fcf100d1db58977c
|
4
|
+
data.tar.gz: ffadfd66bda44da8e748859ee7fa70fe40eb72459e90853a5ab2c8e623dfe172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55808dd79ed3bcef10f4af8d8b65d1090a16b27113d6205116fcdc53630907e90a31487d65745ac3f5f519c48a09449c440653064040d85986802f64fae9b975
|
7
|
+
data.tar.gz: 3ca513e0ecf507fad318218144e22622b91c5ac8be7d4945e6e70d956c7fab755ca06071dd971ad988f7c4fd5bafb732267a3a2fba6ed75bb496fe2552484054
|
data/lib/tiny_bus.rb
CHANGED
@@ -81,23 +81,34 @@ class TinyBus
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# adds a subscriber to a topic
|
84
|
+
#
|
85
|
+
# - topic: either a String, or an array of String
|
86
|
+
# - subber: an object that responds to #msg that can receive messages
|
84
87
|
def sub(topic, subber)
|
85
88
|
raise TinyBus::SubscriberDoesNotMsg.new("The specified subscriber type `#{subber.class.inspect}' does not respond to #msg") unless subber.respond_to?(:msg)
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
topics = topic.is_a?(Array) ? topic : [topic]
|
91
|
+
|
92
|
+
topics.each do |t|
|
93
|
+
@dead_topics.delete(t)
|
94
|
+
@subs[t] ||= Set.new
|
95
|
+
@subs[t] << subber
|
96
|
+
@stats[t] ||= 0
|
91
97
|
|
92
|
-
|
98
|
+
msg({ @topic_key => 'sub', 'to_topic' => t, 'subber' => _to_subber_id(subber) }, 'TINYBUS-SUB')
|
99
|
+
end
|
93
100
|
end
|
94
101
|
|
95
102
|
# removes a subscriber from a topic
|
96
103
|
def unsub(topic, subber)
|
97
|
-
|
98
|
-
|
104
|
+
topics = topic.is_a?(Array) ? topic : [topic]
|
105
|
+
|
106
|
+
topics.each do |t|
|
107
|
+
@subs[t]&.delete(subber)
|
108
|
+
@dead_topics << t if @subs[t].empty?
|
99
109
|
|
100
|
-
|
110
|
+
msg({ @topic_key => 'unsub', 'from_topic' => t, 'subber' => _to_subber_id(subber) }, 'TINYBUS-UNSUB')
|
111
|
+
end
|
101
112
|
end
|
102
113
|
|
103
114
|
def _to_subber_id(subber)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tiny_log
|