local_bus 0.1.0 → 0.1.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/README.md +55 -1
- data/lib/local_bus/bus.rb +1 -0
- data/lib/local_bus/station.rb +1 -2
- data/lib/local_bus/subscriber.rb +4 -1
- data/lib/local_bus/version.rb +1 -1
- 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: fa03fc7b7c1f5e14bff852435b75e343f150ceee9b5f9638ce365918bc39c939
|
4
|
+
data.tar.gz: 1aa8d5ffa9895245ff78f1b00c2d4f3697a1183afe82dc4bcd3d7c420453e924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e17c54a44652eac0c7edb7715a1db68507a0b82b4c3acdd9bfbc4e41d5741b5b80965d623be8e369c4080e43a0cb8696431d6464588655ecc863c47d8bf81e6
|
7
|
+
data.tar.gz: 57fbbe8719669a3dbee59252c2d71ce20c1ce232110779ffa9bf8fa4c68e7da1b59cb9fb916d308c7e8d21e499117eb74b4a5e464db2c0eab2866e53855d9c12
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ Both interfaces ensure optimal performance:
|
|
87
87
|
Best for real-time operations like logging, metrics, and state updates.
|
88
88
|
|
89
89
|
```ruby
|
90
|
-
bus = LocalBus.instance.bus
|
90
|
+
bus = LocalBus::Bus.new # ... or LocalBus.instance.bus
|
91
91
|
|
92
92
|
bus.subscribe "user.created" do |message|
|
93
93
|
AuditLog.record(message.payload)
|
@@ -101,6 +101,33 @@ result.wait # blocks until all subscribers complete
|
|
101
101
|
result.value # blocks and waits until all subscribers complete and returns the subscribers
|
102
102
|
```
|
103
103
|
|
104
|
+
Subscribe with an explicit `callable`.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
callable = ->(message) { "Received message: #{message.payload}" }
|
108
|
+
LocalBus.instance.bus.subscribe "user.created", callable: callable
|
109
|
+
|
110
|
+
subscribers = LocalBus.instance.bus.publish("user.created", user_id: 123).value
|
111
|
+
# => [#<LocalBus::Subscriber:0x0000000126b7cf38 ...>]
|
112
|
+
|
113
|
+
subscribers.first.value
|
114
|
+
# => "Received message: {:user_id=>123}"
|
115
|
+
|
116
|
+
# you can use any object that responds to #call
|
117
|
+
class ExampleCallable
|
118
|
+
def call(message)
|
119
|
+
"Received message: #{message.payload}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
LocalBus.instance.bus.subscribe "user.created", callable: ExampleCallable.new
|
124
|
+
subscribers = LocalBus.instance.bus.publish("user.created", user_id: 123).value
|
125
|
+
# => [#<LocalBus::Subscriber:0x0000000126b7cf38 ...>]
|
126
|
+
|
127
|
+
subscribers.first.value
|
128
|
+
# => "Received message: {:user_id=>123}"
|
129
|
+
```
|
130
|
+
|
104
131
|
### Station (background processing)
|
105
132
|
|
106
133
|
Best for async operations like emails, notifications, and resource-intensive tasks.
|
@@ -120,6 +147,33 @@ result.wait # blocks until all subscribers complete
|
|
120
147
|
result.value # blocks and waits until all subscribers complete and returns the subscribers
|
121
148
|
```
|
122
149
|
|
150
|
+
Subscribe with an explicit `callable`.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
callable = ->(message) { "Received message: #{message.payload}" }
|
154
|
+
LocalBus.instance.station.subscribe "email.welcome", callable: callable
|
155
|
+
|
156
|
+
subscribers = LocalBus.instance.station.publish("email.welcome", user_id: 123).value
|
157
|
+
# => [#<LocalBus::Subscriber:0x0000000126b7cf38 ...>]
|
158
|
+
|
159
|
+
subscribers.first.value
|
160
|
+
# => "Received message: {:user_id=>123}"
|
161
|
+
|
162
|
+
# you can use any object that responds to #call
|
163
|
+
class ExampleCallable
|
164
|
+
def call(message)
|
165
|
+
"Received message: #{message.payload}"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
LocalBus.instance.station.subscribe "email.welcome", callable: ExampleCallable.new
|
170
|
+
subscribers = LocalBus.instance.station.publish("email.welcome", user_id: 123).value
|
171
|
+
# => [#<LocalBus::Subscriber:0x0000000126b7cf38 ...>]
|
172
|
+
|
173
|
+
subscribers.first.value
|
174
|
+
# => "Received message: {:user_id=>123}"
|
175
|
+
```
|
176
|
+
|
123
177
|
## Advanced Usage & Considerations
|
124
178
|
|
125
179
|
### Concurrency Controls
|
data/lib/local_bus/bus.rb
CHANGED
data/lib/local_bus/station.rb
CHANGED
@@ -124,8 +124,7 @@ class LocalBus
|
|
124
124
|
# @rbs &block: (Message) -> untyped -- alternative way to provide a callable
|
125
125
|
# @rbs return: self
|
126
126
|
def subscribe(topic, callable: nil, &block)
|
127
|
-
callable
|
128
|
-
bus.subscribe(topic, &callable)
|
127
|
+
bus.subscribe(topic, callable: callable || block)
|
129
128
|
self
|
130
129
|
end
|
131
130
|
|
data/lib/local_bus/subscriber.rb
CHANGED
@@ -27,7 +27,10 @@ class LocalBus
|
|
27
27
|
@callable = callable
|
28
28
|
@message = message
|
29
29
|
@id = callable.object_id
|
30
|
-
@source_location = callable
|
30
|
+
@source_location = case callable
|
31
|
+
in Proc then callable.source_location
|
32
|
+
else callable.method(:call).source_location
|
33
|
+
end
|
31
34
|
@metadata = {}
|
32
35
|
end
|
33
36
|
|
data/lib/local_bus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hopkins (hopsoft)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|