diff --git a/lib/async/service/supervisor/supervised.rb b/lib/async/service/supervisor/supervised.rb index 62b2847..e5b8375 100644 --- a/lib/async/service/supervisor/supervised.rb +++ b/lib/async/service/supervisor/supervised.rb @@ -78,7 +78,7 @@ def supervisor_worker(state: nil) def prepare!(instance, state: nil) super(instance) - supervisor_worker(state: state).run + return supervisor_worker(state: state).tap(&:run) 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"