Skip to content

Return the Worker as documented from Supervised#prepare! - #11

Closed
tavianator wants to merge 2 commits into
socketry:mainfrom
tavianator:return-the-worker
Closed

Return the Worker as documented from Supervised#prepare!#11
tavianator wants to merge 2 commits into
socketry:mainfrom
tavianator:return-the-worker

Conversation

@tavianator

Copy link
Copy Markdown

Types of Changes

  • Bug fix.

Contribution

Comment thread lib/async/service/supervisor/supervised.rb Outdated
@ioquatix

ioquatix commented Sep 1, 2026

Copy link
Copy Markdown
Member

It's not guaranteed that prepare! will return a worker. What problem are you trying to solve with this change?

@tavianator

Copy link
Copy Markdown
Author

It's not guaranteed that prepare! will return a worker.

The docs say it returns the worker:

# Create a supervised worker for the given instance.
#
# @parameter instance [Async::Container::Instance] The container instance.
# @parameter state [Hash | Nil] Additional state to register with the supervisor.
# @returns [Worker] The worker client.
def prepare!(instance, state: nil)

Could change the docs instead.

What problem are you trying to solve with this change?

I don't think what I was doing when I ran into this was the right approach anyway, but I had overridden prepare! to start a recurring task to provide some metrics from the worker process and I wanted to get the utilization_registry from the worker, so I tried something like

def prepare!(instance)
  worker = super
  do_something_with(worker.utilization_registry)
  worker
end

@samuel-williams-shopify

Copy link
Copy Markdown
Contributor

For now, I'll close this PR, as I'm not sure it solves the right problem. If you want to augment the worker, you'd be better off wrapping supervised_worker. Thanks for your effort and follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants