Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Conversation

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich alex-oleshkevich commented Mar 27, 2024

This PR allows usage of custom user backends. Users can build their own backends and not be dependent on the shipped backends.

backend = MemoryBackend("")
async with Broadcast(backend=backend) as broadcast:
    async with broadcast.subscribe("chatroom") as subscriber:
        await broadcast.publish("chatroom", "hello")
        event = await subscriber.get()
        assert event.channel == "chatroom"
        assert event.message == "hello"

Also closes #90

@alex-oleshkevich
Copy link
Contributor Author

@encode/maintainers anyone?

import pytest

from broadcaster import Broadcast
from broadcaster._backends.memory import MemoryBackend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐼 Can we test against public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have public API for backends. If we reexport them in __init__.py then they will raise import errors because of missing dependencies. This is quite a big, unrelated change.
Or, alternatively, we can rename _backends -> backends making this public. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah understood.

Given the intent of this PR perhaps the test could be against broadcaster.BroadcastBackend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broadcaster.BroadcastBackend is an abstract class. Do you mean extending it for this particular case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.
For httpx we have a policy of only testing against the public API, which seems a good pattern.
We could be following this here also, right?

Copy link
Contributor

@lovelydinosaur lovelydinosaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks.
Couple of suggestions.

alex-oleshkevich and others added 2 commits April 4, 2024 10:32
Co-authored-by: Tom Christie <tom@tomchristie.com>
Comment on lines +80 to +81
backend = CustomBackend("")
async with Broadcast(backend=backend) as broadcast:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@alex-oleshkevich alex-oleshkevich merged commit eeb09de into encode:master Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot provide my own BroadcastBackend

2 participants