ractor-pool 0.1.1 → 0.1.3

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: 62dd226609168199a591e9a2dd8b40c097feabadcd7b9611681cbc18e6eee488
4
- data.tar.gz: 833705c208369f589ad38db761da4af588826d1eeed1787cdbc6537a6134aa67
3
+ metadata.gz: cccb1804757e873a03a33ad500bc670bbe6c15fea30aed69997150b0575ac5f9
4
+ data.tar.gz: 04c10358846e174157d1afc063b57357b9406593c2b8d5633c604d34c2aea468
5
5
  SHA512:
6
- metadata.gz: 9a7ed5170cd7f715da48bfb885e2ed997a0552b5c15dfb89780bc8bf4fb85357caba18992f4511c0ffb10879cf5e85034d556b22bf431960fd7d14475b805a10
7
- data.tar.gz: 1e17f29b590da385d4f0618336912bd283b84e1a011b9044d149b9e6570ec949174c9a69bfbe8e1adc14496d4c0a5c267f8a21d0737eea01e3b33de76fb694e8
6
+ metadata.gz: 96415baf0c0cd793167157cd2c0548c8d505749987adbed28eaea02ad68172f75723b58df6043da22c1fd8ab4940ebff5eeaae9c53d99ec6c124d554e91cfc32
7
+ data.tar.gz: 0f185f8d1c0fb935e214a914976004e9a68115331511449c3166a9114bb3e05e08b855033a7d91176c9e45e9d4fc8f6d1e480e82ac1918c7baefe2e40f7b9d63
@@ -1,14 +1,13 @@
1
1
  steps:
2
2
  - label: ":ruby: Ruby master-dev"
3
+ image: "rubylang/ruby:master-dev"
3
4
  commands:
4
5
  - apt-get update && apt-get install -y libyaml-dev
5
6
  - bundle install
6
7
  - bundle exec rake
7
- plugins:
8
- - docker#v5.13.0:
9
- image: "rubylang/ruby:master-dev"
10
8
 
11
9
  # - label: ":ruby: Ruby {{matrix.ruby}}"
10
+ # image: "ruby:{{matrix.ruby}}"
12
11
  # commands:
13
12
  # - bundle install
14
13
  # - bundle exec rake
@@ -16,6 +15,3 @@ steps:
16
15
  # setup:
17
16
  # ruby:
18
17
  # - 3.5.0
19
- # plugins:
20
- # - docker#v5.13.0:
21
- # image: "ruby:{{matrix.ruby}}"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.3] - 2025-10-31
4
+
5
+ - Allow `:worker` to be a Proc, not just a lambda
6
+
7
+ ## [0.1.2] - 2025-10-29
8
+
9
+ - Fix `@coordinator` RBS type to allow nil
10
+
3
11
  ## [0.1.1] - 2025-10-29
4
12
 
5
13
  - Make `RactorPool::SHUTDOWN` private
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # RactorPool
2
2
 
3
+ ![Version](https://img.shields.io/gem/v/ractor-pool)
4
+ ![Build](https://badge.buildkite.com/f5f08eba1c869dee6e9e87dd66b241059d8fbefaaed6c56d86.svg)
5
+
6
+ A thread-safe, lock-free pool of Ractor workers with a coordinator pattern for distributing work.
7
+
3
8
  ## Installation
4
9
 
5
10
  Install the gem and add to the application's Gemfile by executing:
@@ -19,7 +24,7 @@ gem install ractor-pool
19
24
  Calculating Fibonacci numbers in parallel:
20
25
 
21
26
  ```ruby
22
- fib_worker = lambda do |index|
27
+ fib_worker = proc do |index|
23
28
  first, second = 0, 1
24
29
  index.times { first, second = second, first + second }
25
30
  [index, first]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RactorPool
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/ractor-pool.rb CHANGED
@@ -24,7 +24,7 @@ Warning.ignore(/Ractor is experimental/, __FILE__)
24
24
  #
25
25
  # @example Without result handler
26
26
  # counter = Atom.new(0)
27
- # worker = lambda do |work|
27
+ # worker = proc do |work|
28
28
  # counter.swap { |current_value| current_value + 1 }
29
29
  # work * 2
30
30
  # end
@@ -57,19 +57,19 @@ class RactorPool
57
57
  # @rbs @result_handler: (^(untyped) -> void | nil)
58
58
  # @rbs @state: Atom[Hash[Symbol, bool | Integer]]
59
59
  # @rbs @result_port: Ractor::Port?
60
- # @rbs @coordinator: Ractor
60
+ # @rbs @coordinator: Ractor?
61
61
  # @rbs @workers: Array[Ractor]
62
62
  # @rbs @collector: Thread?
63
63
 
64
64
  # Creates a new RactorPool with the specified number of workers.
65
65
  #
66
66
  # @param size [Integer] number of worker ractors to create
67
- # @param worker [Proc] a shareable lambda that processes each work item
67
+ # @param worker [Proc] a shareable proc that processes each work item
68
68
  # @param name [String, nil] optional name for the pool, used in thread/ractor names
69
- # @yieldparam result [Object] the result returned by the worker lambda
69
+ # @yieldparam result [Object] the result returned by the worker proc
70
70
  # @return [void]
71
71
  # @raise [ArgumentError] if size is not a positive integer
72
- # @raise [ArgumentError] if worker is not a lambda
72
+ # @raise [ArgumentError] if worker is not a proc
73
73
  #
74
74
  # @example With result handler
75
75
  # pool = RactorPool.new(size: 4, worker: -> { it }) { |result| puts result }
@@ -80,10 +80,10 @@ class RactorPool
80
80
  # @rbs (?size: Integer, worker: ^(untyped) -> untyped, ?name: String?) ?{ (untyped) -> void } -> void
81
81
  def initialize(size: Etc.nprocessors, worker:, name: nil, &result_handler)
82
82
  raise ArgumentError, "size must be a positive Integer" unless size.is_a?(Integer) && size > 0
83
- raise ArgumentError, "worker must be a lambda Proc" unless worker.lambda?
83
+ raise ArgumentError, "worker must be a Proc" unless worker.is_a?(Proc)
84
84
 
85
85
  @size = size
86
- @worker = Ractor.shareable_lambda(&worker)
86
+ @worker = Ractor.shareable_proc(&worker)
87
87
  @name = name
88
88
  @result_handler = result_handler
89
89
 
@@ -18,7 +18,7 @@
18
18
  #
19
19
  # @example Without result handler
20
20
  # counter = Atom.new(0)
21
- # worker = lambda do |work|
21
+ # worker = proc do |work|
22
22
  # counter.swap { |current_value| current_value + 1 }
23
23
  # work * 2
24
24
  # end
@@ -48,7 +48,7 @@ class RactorPool
48
48
 
49
49
  @workers: Array[Ractor]
50
50
 
51
- @coordinator: Ractor
51
+ @coordinator: Ractor?
52
52
 
53
53
  @result_port: Ractor::Port?
54
54
 
@@ -65,12 +65,12 @@ class RactorPool
65
65
  # Creates a new RactorPool with the specified number of workers.
66
66
  #
67
67
  # @param size [Integer] number of worker ractors to create
68
- # @param worker [Proc] a shareable lambda that processes each work item
68
+ # @param worker [Proc] a shareable proc that processes each work item
69
69
  # @param name [String, nil] optional name for the pool, used in thread/ractor names
70
- # @yieldparam result [Object] the result returned by the worker lambda
70
+ # @yieldparam result [Object] the result returned by the worker proc
71
71
  # @return [void]
72
72
  # @raise [ArgumentError] if size is not a positive integer
73
- # @raise [ArgumentError] if worker is not a lambda
73
+ # @raise [ArgumentError] if worker is not a proc
74
74
  #
75
75
  # @example With result handler
76
76
  # pool = RactorPool.new(size: 4, worker: -> { it }) { |result| puts result }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ractor-pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young