local_bus 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc19202ff3881f3519fd8cfe760b7b83f42fff39cb2b9658d2550fbd2b0bcca0
4
- data.tar.gz: 2d2fc75beaa51eb84f2263dc82aa0049c3c2f51b24c32939f911c0b774ef74f9
3
+ metadata.gz: f6f1119ac19b5642c84099312240ce0baf8320b42098cb48c918b627385a5aff
4
+ data.tar.gz: 936a119be41c3885de3d27bf7a68effb07bbda58fe0856e8ca7043b76bfbfe47
5
5
  SHA512:
6
- metadata.gz: 44e7b2c60c2be6b5435cc1a652ee624502b775ee503662f582cb32d884e082cb47ee2b8159a27080e820530988aaa4cc5fc3e47f420629d9a0a0b3be7b0a665d
7
- data.tar.gz: 647481ca9e89a0239e26ea622c8551757d991595f52a1ba3aac06a0ac03a7266a8f42253dbd8cec30311361d49a2ed2bdd80e95f62648365d95e817de2a34853
6
+ metadata.gz: ad441d27aacd1447fd9cebc7aaa5b55ab79b75eb6ce8ed756fc6f11d8b77203412796ce724067707e4c859fd28c384c16c2a6abe56139e4df3a727bd76cc104b
7
+ data.tar.gz: be8cc2ed7325347e6b3447777144dce7992fdc07385f0e20af8cfe300834c7cfe651fd7b6b0ffc9bdd797fb439ad702095220e8caa5a3c20651deae647fc97a0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Lines of Code](https://img.shields.io/badge/loc-364-47d299.svg)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
1
+ [![Lines of Code](https://img.shields.io/badge/loc-365-47d299.svg)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![GEM Version](https://img.shields.io/gem/v/local_bus)](https://rubygems.org/gems/local_bus)
3
3
  [![GEM Downloads](https://img.shields.io/gem/dt/local_bus)](https://rubygems.org/gems/local_bus)
4
4
  [![Tests](https://github.com/hopsoft/local_bus/actions/workflows/tests.yml/badge.svg)](https://github.com/hopsoft/local_bus/actions)
@@ -205,6 +205,13 @@ message.subscribers # blocks and waits until all subscribers complete and return
205
205
 
206
206
  message.subscribers.first.value
207
207
  #=> "It worked!"
208
+
209
+ # subscribe with any object that responds to `#call`.
210
+ worker = ->(message) do
211
+ # business logic (e.g. API calls, database queries, disk operations, etc.)
212
+ "It worked!"
213
+ end
214
+ LocalBus.subscribe "user.created", callable: worker
208
215
  ```
209
216
 
210
217
  ### Bus
@@ -215,6 +222,7 @@ bus = LocalBus::Bus.new # ... or LocalBus.instance.bus
215
222
  # register a subscriber
216
223
  bus.subscribe "user.created" do |message|
217
224
  # business logic (e.g. API calls, database queries, disk operations, etc.)
225
+ "It worked!"
218
226
  end
219
227
 
220
228
  message = bus.publish("user.created", user_id: 123)
@@ -222,12 +230,8 @@ message.wait # blocks until all subscribers complete
222
230
  message.subscribers # waits and returns the subscribers
223
231
  #=> [#<LocalBus::Subscriber:0x000000012bbb79a8 ...>]
224
232
 
225
- # subscribe with any object that responds to `#call`.
226
- worker = ->(message) do
227
- # business logic (e.g. API calls, database queries, disk operations, etc.)
228
- "It worked!"
229
- end
230
- bus.subscribe "user.created", callable: worker
233
+ message.subscribers.first.value
234
+ #=> "It worked!"
231
235
  ```
232
236
 
233
237
  ### Station
@@ -247,13 +251,6 @@ message.subscribers # blocks and waits until all subscribers complete and return
247
251
 
248
252
  message.subscribers.first.value
249
253
  #=> "It worked!"
250
-
251
- # subscribe with any object that responds to `#call`.
252
- worker = ->(message) do
253
- # business logic (e.g. API calls, database queries, disk operations, etc.)
254
- "It worked!"
255
- end
256
- station.subscribe "user.created", callable: worker
257
254
  ```
258
255
 
259
256
  ## Advanced Usage
@@ -377,12 +374,11 @@ bin/demo-bus # demonstrates Bus performance
377
374
  bin/demo-station # demonstrates Station performance
378
375
  ```
379
376
 
380
- Both demos simulate I/O-bound operations _(1 second latency per subscriber)_ to show how LocalBus handles concurrent processing. For example, on an 10-core system:
381
-
382
- - The Bus processes a message with 10 I/O-bound subscribers in ~1 second instead of 10 seconds
383
- - The Station processes 10 messages with 10 I/O-bound subscribers each in ~1 second instead of 100 seconds
377
+ Both demos simulate I/O-bound operations _(1 second latency per subscriber)_ to show how LocalBus handles concurrent processing.
384
378
 
385
- This demonstrates how LocalBus offers high throughput for I/O-bound operations. :raised_hands:
379
+ For example,
380
+ LocalBus can process 10 messages with 10 I/O-bound subscribers each in **~1 second instead of 100 seconds**,
381
+ on a 10-core system.
386
382
 
387
383
  ## See Also
388
384
 
data/lib/local_bus/bus.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  class LocalBus
6
4
  # The Bus acts as a direct transport mechanism for messages, akin to placing a passenger directly onto a bus.
7
5
  # When a message is published to the Bus, it is immediately delivered to all subscribers, ensuring prompt execution of tasks.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  class LocalBus
6
4
  # Represents a message in the LocalBus system
7
5
  class Message
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  class LocalBus
6
4
  # Wraps an Async::Barrier and a list of Subscribers that are processing a Message.
7
5
  class Publication
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
- # rubocop:disable Lint/MissingCopEnableDirective
5
- # rubocop:disable Style/ArgumentsForwarding
6
-
7
3
  class LocalBus
8
4
  # The Station serves as a queuing system for messages, similar to a bus station where passengers wait for their bus.
9
5
  #
@@ -28,16 +24,17 @@ class LocalBus
28
24
  # Will not delay process exit when the queue is empty.
29
25
  #
30
26
  # @rbs bus: Bus -- local message bus (default: Bus.new)
31
- # @rbs interval: Float -- queue polling interval in seconds (default: 0.01)
27
+ # @rbs interval: Float -- queue polling interval in seconds (default: 0.1)
32
28
  # @rbs limit: Integer -- max queue size (default: 10_000)
33
29
  # @rbs threads: Integer -- number of threads to use (default: Etc.nprocessors)
34
30
  # @rbs timeout: Float -- seconds to wait for subscribers to process the message before cancelling (default: 60)
35
31
  # @rbs wait: Float -- seconds to wait for the queue to flush at process exit (default: 5)
36
32
  # @rbs return: void
37
- def initialize(bus: Bus.new, interval: 0.01, limit: 10_000, threads: Etc.nprocessors, timeout: 60, wait: 5)
33
+ def initialize(bus: Bus.new, interval: 0.1, limit: 10_000, threads: Etc.nprocessors, timeout: 60, wait: 5)
38
34
  super()
39
35
  @bus = bus
40
- @interval = [interval.to_f, 0.01].max
36
+ @interval = interval.to_f
37
+ @interval = 0.1 unless @interval.positive?
41
38
  @limit = limit.to_i.positive? ? limit.to_i : 10_000
42
39
  @threads = [threads.to_i, 1].max
43
40
  @timeout = timeout.to_f
@@ -67,11 +64,11 @@ class LocalBus
67
64
  attr_reader :timeout
68
65
 
69
66
  # Starts the station
70
- # @rbs interval: Float -- queue polling interval in seconds (default: 0.01)
67
+ # @rbs interval: Float -- queue polling interval in seconds (default: self.interval)
71
68
  # @rbs threads: Integer -- number of threads to use (default: self.threads)
72
69
  # @rbs return: void
73
70
  def start(interval: self.interval, threads: self.threads)
74
- interval = [interval.to_f, 0.01].max
71
+ interval = 0.1 unless interval.positive?
75
72
  threads = [threads.to_i, 1].max
76
73
 
77
74
  synchronize do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  class LocalBus
6
4
  # Wraps a Callable (Proc) and Message intended for asynchronous execution.
7
5
  class Subscriber
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  class LocalBus
6
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
7
5
  end
data/lib/local_bus.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  require "zeitwerk"
6
4
  loader = Zeitwerk::Loader.for_gem
7
5
  loader.setup
@@ -25,7 +25,7 @@ class LocalBus
25
25
  # Will not delay process exit when the queue is empty.
26
26
  #
27
27
  # @rbs bus: Bus -- local message bus (default: Bus.new)
28
- # @rbs interval: Float -- queue polling interval in seconds (default: 0.01)
28
+ # @rbs interval: Float -- queue polling interval in seconds (default: 0.1)
29
29
  # @rbs limit: Integer -- max queue size (default: 10_000)
30
30
  # @rbs threads: Integer -- number of threads to use (default: Etc.nprocessors)
31
31
  # @rbs timeout: Float -- seconds to wait for subscribers to process the message before cancelling (default: 60)
@@ -54,7 +54,7 @@ class LocalBus
54
54
  attr_reader timeout: untyped
55
55
 
56
56
  # Starts the station
57
- # @rbs interval: Float -- queue polling interval in seconds (default: 0.01)
57
+ # @rbs interval: Float -- queue polling interval in seconds (default: self.interval)
58
58
  # @rbs threads: Integer -- number of threads to use (default: self.threads)
59
59
  # @rbs return: void
60
60
  def start: (?interval: Float, ?threads: Integer) -> void
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.3.0
4
+ version: 0.3.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-12-03 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: algorithms
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  - !ruby/object:Gem::Version
268
268
  version: '0'
269
269
  requirements: []
270
- rubygems_version: 3.5.21
270
+ rubygems_version: 3.5.23
271
271
  signing_key:
272
272
  specification_version: 4
273
273
  summary: A lightweight pub/sub system for decoupled intra-process communication in