ractor-dispatch 0.1.0 → 0.2.0
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 +2 -0
- data/lib/ractor/dispatch/executor.rb +21 -1
- data/lib/ractor/dispatch/version.rb +1 -1
- data/lib/ractor/dispatch.rb +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a1ca6e784df09f46829e6d18c22397fd449a7249dd20f3e840b25d6e6dd97f4
|
|
4
|
+
data.tar.gz: 861edd63d520247c6bf63ca123ba7b65028f68f2f781814fbd2594cf8b55e94f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '080100e7eca91ac6062213ec5bc48e52395c9242ebd898d7e51b77383db3634954b83782df9052570a9be2e9739f3476beebd0cd4e7b775c7e1bbd87a7a094eb'
|
|
7
|
+
data.tar.gz: 2ea990ca0dff1476c34bd6064c5489530d9d1f7e490c64b35c60c49e337a9478199bb1ff805cffed4631028decb553b4b999ac4893a46d3ce4830166470a6f09
|
data/README.md
CHANGED
|
@@ -76,6 +76,8 @@ reply ports naturally route results back to the correct caller.
|
|
|
76
76
|
|
|
77
77
|
Requires Ruby with `Ractor::Port` support (Ruby 4.0+).
|
|
78
78
|
|
|
79
|
+
It installs and can be required on Ruby 3.3+, but attempting to use the library will raise.
|
|
80
|
+
|
|
79
81
|
## Development
|
|
80
82
|
|
|
81
83
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
class Ractor
|
|
4
4
|
module Dispatch
|
|
5
|
+
class Unsupported < StandardError; end
|
|
6
|
+
|
|
5
7
|
class Executor
|
|
6
8
|
def initialize
|
|
7
|
-
@port =
|
|
9
|
+
@port =
|
|
10
|
+
begin
|
|
11
|
+
Ractor::Port.new
|
|
12
|
+
rescue NameError
|
|
13
|
+
raise Unsupported, "Ractor-dispatch requires Ractor::Port (Ruby 4.0+)"
|
|
14
|
+
end
|
|
8
15
|
|
|
9
16
|
Thread.new do
|
|
10
17
|
loop do
|
|
@@ -17,6 +24,8 @@ class Ractor
|
|
|
17
24
|
rescue Ractor::ClosedError
|
|
18
25
|
# caller went away, discard
|
|
19
26
|
end
|
|
27
|
+
rescue Ractor::Error => e
|
|
28
|
+
reply_port << [:error, Ractor::Dispatch::Error.new("Executor encountered a problem", details: serialize_error(e))]
|
|
20
29
|
end
|
|
21
30
|
rescue Ractor::ClosedError
|
|
22
31
|
# port closed via shutdown
|
|
@@ -39,6 +48,17 @@ class Ractor
|
|
|
39
48
|
def shutdown
|
|
40
49
|
@port.close
|
|
41
50
|
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def serialize_error(error)
|
|
55
|
+
{
|
|
56
|
+
class: error.class,
|
|
57
|
+
message: error.message&.to_s,
|
|
58
|
+
backtrace: error.backtrace&.map(&:to_s),
|
|
59
|
+
cause: error.cause && serialize_error(error.cause)
|
|
60
|
+
}
|
|
61
|
+
end
|
|
42
62
|
end
|
|
43
63
|
end
|
|
44
64
|
end
|
data/lib/ractor/dispatch.rb
CHANGED
|
@@ -6,7 +6,14 @@ require_relative "dispatch/executor"
|
|
|
6
6
|
|
|
7
7
|
class Ractor
|
|
8
8
|
module Dispatch
|
|
9
|
-
class Error < StandardError
|
|
9
|
+
class Error < StandardError
|
|
10
|
+
attr_reader :details
|
|
11
|
+
|
|
12
|
+
def initialize(message = nil, details: nil)
|
|
13
|
+
@details = details
|
|
14
|
+
super(message)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
10
17
|
|
|
11
18
|
@main = Executor.new
|
|
12
19
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ractor-dispatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Hawthorn
|
|
@@ -40,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version:
|
|
43
|
+
version: '3.3'
|
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
48
|
version: '0'
|
|
49
49
|
requirements: []
|
|
50
|
-
rubygems_version:
|
|
50
|
+
rubygems_version: 3.6.9
|
|
51
51
|
specification_version: 4
|
|
52
52
|
summary: Dispatch work to a specific Ractor and get results back
|
|
53
53
|
test_files: []
|