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

Subject should implement AsyncContextManager for auto-unsubscribe #585

Open
skewty opened this issue Jul 10, 2024 · 1 comment
Open

Subject should implement AsyncContextManager for auto-unsubscribe #585

skewty opened this issue Jul 10, 2024 · 1 comment
Assignees
Labels
proposal Enhancement idea or proposal

Comments

@skewty
Copy link

skewty commented Jul 10, 2024

Proposed change

class Subject:
    async def __aenter__(self):
        return self

    async def __aexit__(self, *args, **kwargs):
        await self.unsubscribe()

Use case

async with AsyncExitStack() as stack:
    nc = await nats.connect()
    await stack.enter_async_context(nc)
    await stack.enter_async_context(await nc.subscribe(...))
    await stack.enter_async_context(await nc.subscribe(...))

Contribution

No response

@skewty skewty added the proposal Enhancement idea or proposal label Jul 10, 2024
@caspervonb caspervonb self-assigned this Jul 14, 2024
@caspervonb
Copy link
Contributor

On Subscription? but yes, pull request very welcome 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

2 participants