Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a @pub kwarg to allow specifying a "startup response message" #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tractor/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def pub(
wrapped: typing.Callable = None,
*,
tasks: Set[str] = set(),
send_on_connect: Any = None,
):
"""Publisher async generator decorator.

Expand Down Expand Up @@ -206,7 +207,7 @@ async def pub_service(get_topics):

# handle the decorator not called with () case
if wrapped is None:
return partial(pub, tasks=tasks)
return partial(pub, tasks=tasks, send_on_connect=send_on_connect)

task2lock: Dict[str, trio.StrictFIFOLock] = {}

Expand Down Expand Up @@ -249,6 +250,11 @@ async def _execute(

try:
modify_subs(topics2ctxs, topics, ctx)

# if specified send the startup message back to consumer
if send_on_connect is not None:
await ctx.send_yield(send_on_connect)

# block and let existing feed task deliver
# stream data until it is cancelled in which case
# the next waiting task will take over and spawn it again
Expand Down