From 63c4878042513d4603a2155b37a07a47e1217f35 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 17 Aug 2026 16:42:27 -0400 Subject: [PATCH 1/2] Return the Worker as documented from Supervised#prepare! --- lib/async/service/supervisor/supervised.rb | 5 ++++- test/async/service/supervised.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/async/service/supervisor/supervised.rb b/lib/async/service/supervisor/supervised.rb index 62b2847..72bb65b 100644 --- a/lib/async/service/supervisor/supervised.rb +++ b/lib/async/service/supervisor/supervised.rb @@ -78,7 +78,10 @@ def supervisor_worker(state: nil) def prepare!(instance, state: nil) super(instance) - supervisor_worker(state: state).run + worker = supervisor_worker(state: state) + worker.run + + worker end end end diff --git a/test/async/service/supervised.rb b/test/async/service/supervised.rb index 15636b6..06a2d8d 100644 --- a/test/async/service/supervised.rb +++ b/test/async/service/supervised.rb @@ -57,6 +57,24 @@ def setup(container) worker_task&.stop end + it "returns the worker from prepare!" do + environment = Async::Service::Environment.build(root: @root) do + name "simple-service" + + service_class {SimpleService} + + include Async::Service::Managed::Environment + include Async::Service::Supervisor::Supervised + end + + worker = environment.evaluator.prepare!(nil) + expect(worker).to be_a(Async::Service::Supervisor::Worker) + + # Wait for the worker to register with the supervisor: + event = registration_monitor.pop + expect(event.supervisor_controller.process_id).to be == ::Process.pid + end + it "can register explicit worker state" do environment = Async::Service::Environment.build(root: @root) do name "simple-service" From 1bf9eae22ecab2960590d829f00152996822e4a3 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 31 Aug 2026 16:24:15 +1200 Subject: [PATCH 2/2] Apply suggestion from @samuel-williams-shopify --- lib/async/service/supervisor/supervised.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/async/service/supervisor/supervised.rb b/lib/async/service/supervisor/supervised.rb index 72bb65b..e5b8375 100644 --- a/lib/async/service/supervisor/supervised.rb +++ b/lib/async/service/supervisor/supervised.rb @@ -78,10 +78,7 @@ def supervisor_worker(state: nil) def prepare!(instance, state: nil) super(instance) - worker = supervisor_worker(state: state) - worker.run - - worker + return supervisor_worker(state: state).tap(&:run) end end end