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 +4 -4
- data/.buildkite/pipeline.yml +2 -6
- data/CHANGELOG.md +8 -0
- data/README.md +6 -1
- data/lib/ractor-pool/version.rb +1 -1
- data/lib/ractor-pool.rb +7 -7
- data/sig/generated/ractor-pool.rbs +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cccb1804757e873a03a33ad500bc670bbe6c15fea30aed69997150b0575ac5f9
|
|
4
|
+
data.tar.gz: 04c10358846e174157d1afc063b57357b9406593c2b8d5633c604d34c2aea468
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 96415baf0c0cd793167157cd2c0548c8d505749987adbed28eaea02ad68172f75723b58df6043da22c1fd8ab4940ebff5eeaae9c53d99ec6c124d554e91cfc32
|
|
7
|
+
data.tar.gz: 0f185f8d1c0fb935e214a914976004e9a68115331511449c3166a9114bb3e05e08b855033a7d91176c9e45e9d4fc8f6d1e480e82ac1918c7baefe2e40f7b9d63
|
data/.buildkite/pipeline.yml
CHANGED
|
@@ -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
data/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# RactorPool
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
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 =
|
|
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]
|
data/lib/ractor-pool/version.rb
CHANGED
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
83
|
+
raise ArgumentError, "worker must be a Proc" unless worker.is_a?(Proc)
|
|
84
84
|
|
|
85
85
|
@size = size
|
|
86
|
-
@worker = Ractor.
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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 }
|