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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d467750fb7358768f6bdaefc11134e62f60fe642198cf28141ee160563caf43
4
- data.tar.gz: 3974b307afe4d1f32fb1a3aa7989712465fb496a2c98fc475463f606cde1e9d8
3
+ metadata.gz: 6a1ca6e784df09f46829e6d18c22397fd449a7249dd20f3e840b25d6e6dd97f4
4
+ data.tar.gz: 861edd63d520247c6bf63ca123ba7b65028f68f2f781814fbd2594cf8b55e94f
5
5
  SHA512:
6
- metadata.gz: 38c7e36f435c8e9bfbba832bd8ceb313bddcf59d781f939e3079e88aae725c08f112db7ebeb39ad14982467010a5af1f57883443f568b55392a1c6b443415fd1
7
- data.tar.gz: e4d1c7e84f803565684a0b789908d576c0a9f765d2147fb457e8a8a6b50a92d8820722e0d800efe9c2a9e58b1af3a2a2424ff897fb908b39f524f48bfc1f3b27
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 = Ractor::Port.new
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Ractor
4
4
  module Dispatch
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -6,7 +6,14 @@ require_relative "dispatch/executor"
6
6
 
7
7
  class Ractor
8
8
  module Dispatch
9
- class Error < StandardError; end
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.1.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: 4.0.0.dev
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: 4.0.3
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: []