Skip to content

Commit

Permalink
docs: clerify ping callables get services as first argument
Browse files Browse the repository at this point in the history
Fixes #99
  • Loading branch information
hynek committed Aug 18, 2024
1 parent bea7691 commit eab35c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ For instance, you could free a database connection pool in an {mod}`atexit` hand
This liberates you from keeping track of registered services yourself.
You can also use a registry as an (async) context manager that (a)closes automatically on exit.

*svcs* will raise a {class}`ResourceWarning` if a registry with pending cleanups is garbage-collected.
*svcs* will raise a {class}`ResourceWarning` when a registry with pending cleanups is garbage-collected.


## Containers
Expand Down Expand Up @@ -280,7 +280,7 @@ Now the type name expresses the purpose of the object and it doesn't matter if t

Each registered service may have a `ping` callable that you can use for health checks.
You can request all pingable registered services with {meth}`svcs.Container.get_pings()`.
This returns a list of {class}`svcs.ServicePing` objects that currently have a name property to identify the ping and a {meth}`~svcs.ServicePing.ping()` method that instantiates the service, adds it to the cleanup list, and runs the ping.
This returns a list of {class}`svcs.ServicePing` objects that have a name property to identify the ping and a {meth}`~svcs.ServicePing.ping()` method that acquires the service, adds it to the cleanup list, and runs the ping with the acquired service as its only argument.

If you have async services (factory or ping callable), you can use {meth}`~svcs.ServicePing.aping()` instead.
`aping()` works with sync services, too, so you can use it universally in async code.
Expand Down
6 changes: 3 additions & 3 deletions src/svcs/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ class ServicePing:

def ping(self) -> None:
"""
Instantiate the service, schedule its cleanup, and call its ping
method.
Acquire the service, schedule its cleanup, and call its ping callable
with the acquired service as its only argument.
"""
svc: Any = self._container.get(self._svc_type)
self._ping(svc)

async def aping(self) -> None:
"""
Same as :meth:`ping` but instantiate and/or ping asynchronously, if
Same as :meth:`ping` but acquire and/or ping asynchronously, if
necessary.
Also works with synchronous services, so in an async application, just
Expand Down

0 comments on commit eab35c3

Please sign in to comment.