ractor-wrapper 0.3.0 → 0.5.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/.yardopts +1 -0
- data/CHANGELOG.md +22 -0
- data/CLAUDE.md +79 -0
- data/DESIGN.md +1024 -0
- data/README.md +344 -57
- data/lib/ractor/wrapper/version.rb +1 -1
- data/lib/ractor/wrapper.rb +1041 -282
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c9842a8f90ab6b20838f2f79a5b70dd63caf6dd895bb933c116f44f9d994079
|
|
4
|
+
data.tar.gz: 496a5dbd7b8f62aeb889c34e48adb09ec879fc2c382cea8192cf7935a6fec237
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20fb9f04c4824370c120133c72a8927f1131aab29bf134b367b2afc36c19b5be8b42e864ec776f437bd7424b39203c9524a31972a8e4633e2f5915d03168c513
|
|
7
|
+
data.tar.gz: 07d84754548dfc770381aa517812f9d702ae5b7f1ccaea0ec36f7fc8be3a8049080606ba52d34f47b4749d1665f8a06a992a97a394e5ca2c17e08c92672fbc20
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### v0.5.0 / 2026-04-26
|
|
4
|
+
|
|
5
|
+
* ADDED: Reworked server flow to use fibers, to reduce deadlocks on nested calls
|
|
6
|
+
* DOCS: Added design doc
|
|
7
|
+
|
|
8
|
+
### v0.4.0 / 2026-03-30
|
|
9
|
+
|
|
10
|
+
This release includes two major changes: it greatly improves robustness in the case of server crashes, and it reworks the method call configuration interface. This involves several breaking changes, and I expect the interface will continue to be a bit unstable for now as I'm working through use cases and edge cases. The README has also been expanded to include more information on the configuration options and the known issues.
|
|
11
|
+
|
|
12
|
+
* ADDED: Uses a separate `Ractor::Wrapper::Configuration` class for block-based initialization. Removed the configuration mutation methods from `Ractor::Wrapper` itself.
|
|
13
|
+
* BREAKING CHANGE: The method configuration interface now uses symbolic settings values instead of booleans for more flexibility
|
|
14
|
+
* ADDED: Support for suppressing return values for methods and blocks that unintentionally return something they shouldn't
|
|
15
|
+
* BREAKING CHANGE: Raises `Ractor::Wrapper::StoppedError` instead of `Ractor::ClosedError` if a method is called via the wrapper after the wrapper has stopped
|
|
16
|
+
* BREAKING CHANGE: `Wrapper#join` now returns normally rather than raising, if an isolated wrapper terminated due to a crash
|
|
17
|
+
* BREAKING FIX: `Wrapper#join` no longer hangs if a local wrapper crashes, but returns to indicate that the wrapper has stopped (albeit non-normally)
|
|
18
|
+
* FIXED: Internal cleanup is more robust if a crash occurs in the wrapper
|
|
19
|
+
* FIXED: Method calls raise `Ractor::Wrapper::CrashedError` instead of hanging if the wrapper crashes during handling
|
|
20
|
+
* FIXED: Prevented port leaks if a method call send or a block yield send fails
|
|
21
|
+
* FIXED: Methods that return or yield self return/yield the stub instead
|
|
22
|
+
* FIXED: The `recover_object` method now raises `Ractor::Wrapper::Error` if recovery failed
|
|
23
|
+
* DOCS: Updates to README
|
|
24
|
+
|
|
3
25
|
### v0.3.0 / 2026-01-05
|
|
4
26
|
|
|
5
27
|
This is a major update, and the library, while still experimental, is finally somewhat usable. The examples in the README now actually work!
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
This project uses [Toys](https://dazuma.github.io/toys) for task management (not Rake).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Run full CI pipeline
|
|
11
|
+
toys ci
|
|
12
|
+
|
|
13
|
+
# Run individual components
|
|
14
|
+
toys test # Tests only
|
|
15
|
+
toys rubocop # Linting and code style only
|
|
16
|
+
toys yardoc # Documentation only
|
|
17
|
+
toys build # Build gem only
|
|
18
|
+
|
|
19
|
+
# Run a single test file
|
|
20
|
+
toys test test/test_wrapper.rb
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
The entire library lives in `lib/ractor/wrapper.rb`. The public entry point is `Ractor::Wrapper`, which wraps a non-shareable object and exposes it to other Ractors via a shareable `Stub` proxy.
|
|
26
|
+
|
|
27
|
+
### Core classes
|
|
28
|
+
|
|
29
|
+
- **`Ractor::Wrapper`** — Public API. Wraps an object and manages its lifecycle. Accepts options like `use_current_ractor:`, `threads:`, `name:`, and per-method settings via `configure_method`.
|
|
30
|
+
- **`Ractor::Wrapper::Stub`** — Frozen, shareable proxy passed to other Ractors. Uses `method_missing` to forward calls back to the wrapper via message passing.
|
|
31
|
+
- **`Ractor::Wrapper::MethodSettings`** — Frozen configuration controlling copy vs. move semantics for arguments and return values, and block handling behavior.
|
|
32
|
+
- **`Ractor::Wrapper::Server`** — Private backend. Receives `CallMessage` objects and dispatches them to the wrapped object, then returns results via `ReturnMessage`, `ExceptionMessage`, or one of the yield message types (`FiberYieldMessage` or `BlockingYieldMessage`).
|
|
33
|
+
|
|
34
|
+
### Two execution modes
|
|
35
|
+
|
|
36
|
+
1. **Isolated mode** (default) — the wrapped object is moved into a new Ractor. Other Ractors interact with it through the Stub. After `join`, the object can be recovered via `recover_object`.
|
|
37
|
+
2. **Local mode** (`use_current_ractor: true`) — the server runs as Thread(s) inside the current Ractor. The object is never moved. Used for objects that cannot be transferred between Ractors (e.g., SQLite3 connections).
|
|
38
|
+
|
|
39
|
+
### Concurrency within the server
|
|
40
|
+
|
|
41
|
+
- **Sequential** (default) — one call at a time, no worker threads.
|
|
42
|
+
- **Concurrent** — multiple worker threads (set via `threads:`), for thread-safe wrapped objects.
|
|
43
|
+
|
|
44
|
+
### Message protocol
|
|
45
|
+
|
|
46
|
+
All inter-Ractor communication uses frozen message structs defined in the file: `CallMessage`, `ReturnMessage`, `ExceptionMessage`, `FiberYieldMessage`, `BlockingYieldMessage`, `FiberReturnMessage`, `FiberExceptionMessage`, `StopMessage`, `JoinMessage`, `WorkerStoppedMessage`. Block calls round-trip via one of two paths:
|
|
47
|
+
|
|
48
|
+
- **Fiber-suspend path** (most cases): the server sends a `FiberYieldMessage` (carrying the `fiber_id` of the suspended method-handling fiber) to the caller Ractor. The caller executes the block and sends a `FiberReturnMessage` or `FiberExceptionMessage` back to the server's main port; the main loop looks up the fiber by id and resumes it with the reply.
|
|
49
|
+
- **Blocking-fallback path** (nested-fiber/spawned-thread cases): the server allocates a temporary reply port, sends a `BlockingYieldMessage` carrying that port, and blocks on it. The caller responds with a `ReturnMessage` or `ExceptionMessage` directly to that temporary port. This path can deadlock under re-entrant calls but is preserved where the fiber-suspend path is not safe.
|
|
50
|
+
|
|
51
|
+
### Lifecycle
|
|
52
|
+
|
|
53
|
+
1. Wrapper starts → Server enters **running** phase (accepts calls).
|
|
54
|
+
2. `async_stop` or `stop` called → Server enters **stopping** phase (rejects new calls, drains workers).
|
|
55
|
+
3. All workers finish → Server enters **cleanup** phase and shuts down.
|
|
56
|
+
4. `join` returns → In isolated mode, `recover_object` retrieves the wrapped object.
|
|
57
|
+
|
|
58
|
+
## Code Style
|
|
59
|
+
|
|
60
|
+
- Ruby 4.0+ target
|
|
61
|
+
- Double-quoted strings (`Style/StringLiterals: double_quotes`)
|
|
62
|
+
- Trailing commas in multiline arrays and hashes
|
|
63
|
+
- Bracket-style symbol and word arrays (`[:foo, :bar]` not `%i[foo bar]`)
|
|
64
|
+
- Max line length: 120
|
|
65
|
+
- `Style/DocumentationMethod: Enabled` — public methods require YARD docs
|
|
66
|
+
- Tests use Minitest spec style with assertions (not expectations)
|
|
67
|
+
- Top-level constants must be prefixed with `::` (e.g. `::File`, `::Regexp`, `::Gem::Version`) to avoid ambiguous resolution within nested namespaces. Relative constants defined within the current namespace should not be prefixed. Note that Kernel method calls such as `Array(x)`, `Integer(x)`, `Float(x)` look like constants but are not and do not get the prefix.
|
|
68
|
+
|
|
69
|
+
## Testing
|
|
70
|
+
|
|
71
|
+
- Minitest spec style: `describe`/`it` blocks with `assert_*` assertions (not expectations)
|
|
72
|
+
- Test files follow the `test_*.rb` naming convention
|
|
73
|
+
|
|
74
|
+
## General coding instructions
|
|
75
|
+
|
|
76
|
+
- Unless instructed otherwise, always use red-green test-driven development when making code changes. For each step in a coding task, first write tests and confirm they fail. Then write code to make the tests pass.
|
|
77
|
+
- Unless instructed otherwise, always git commit after a step is complete and the tests pass.
|
|
78
|
+
- Conventional Commits format required (`fix:`, `feat:`, `docs:`, etc.)
|
|
79
|
+
- Prefer Ruby for any one-off scripts you need to write as part of your work.
|