ractor-dispatch 0.1.0 → 0.3.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: 3651304d92c5f1fc5612d1a16aca9c153c4bb04956eb39a1bbd575a0d2b138b8
4
+ data.tar.gz: 1e94335e4756f2500906feb931ebe80444603a82a4de2950b55b65a99abf5dcf
5
5
  SHA512:
6
- metadata.gz: 38c7e36f435c8e9bfbba832bd8ceb313bddcf59d781f939e3079e88aae725c08f112db7ebeb39ad14982467010a5af1f57883443f568b55392a1c6b443415fd1
7
- data.tar.gz: e4d1c7e84f803565684a0b789908d576c0a9f765d2147fb457e8a8a6b50a92d8820722e0d800efe9c2a9e58b1af3a2a2424ff897fb908b39f524f48bfc1f3b27
6
+ metadata.gz: c649b4ad209cf4239cda86c8d257975ffb3a93e27ea7bd642418c20f478c2707a823a189974f9ee2ab384a5abfce62dd67f8ca49b93a089e5e326f915890d6ee
7
+ data.tar.gz: '0059beb09aa27024cdda1b98a056cec5c3ae68a6d54e8b8aae8d7f028135b563bcf517461f4c069a8d7ede8b88c2809631db8319ce92384ec09b8dee5c89be2a'
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.3.0"
6
6
  end
7
7
  end
@@ -6,12 +6,37 @@ 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
 
13
- def self.main
14
- @main
20
+ class << self
21
+ def main
22
+ @main
23
+ end
24
+
25
+ def reset_main! # :nodoc:
26
+ @main.shutdown
27
+ @main = Executor.new
28
+ end
15
29
  end
30
+
31
+ module ForkSafety # :nodoc:
32
+ def _fork
33
+ pid = super
34
+ Ractor::Dispatch.reset_main! if pid == 0
35
+ pid
36
+ end
37
+ end
38
+ private_constant :ForkSafety
39
+
40
+ Process.singleton_class.prepend(ForkSafety) if Process.respond_to?(:_fork)
16
41
  end
17
42
  end
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.3.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: 4.0.16
51
51
  specification_version: 4
52
52
  summary: Dispatch work to a specific Ractor and get results back
53
53
  test_files: []