need more documents for groups_for_signal and groups_for_consumer, and what "__" means in the examples #190
Unanswered
Randix6644
asked this question in
FAQ
Replies: 3 comments
-
@Randix6644 could you link to the example in question. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I assume @Randix6644 is referring to the examples in the README here: # consumers.py
from djangochannelsrestframework.consumers import AsyncAPIConsumer
from djangochannelsrestframework.decorators import action
from djangochannelsrestframework.observer import observer
from rest_framework import status
from .signals import joined_chat_signal
from .serializers import UserSerializer
class TestConsumer(AsyncAPIConsumer):
@action()
def join_chat(self, chat_id, **kwargs):
serializer = UserSerializer(instance=self.scope['user'])
joined_chat_signal.send(sender='join_chat', data=serializer.data, **kwargs)
return {}, status.HTTP_204_NO_CONTENT
@observer(signal=joined_chat_signal)
async def joined_chat_handler(self, data, observer=None, action=None, subscribing_request_ids=[], **kwargs):
for request_id in subscribing_request_ids:
await self.reply(action='joined_chat', data=data, status=status.HTTP_200_OK, request_id=request_id)
@joined_chat_handler.serializer
def join_chat_handler(self, sender, data, **kwargs): # the data comes from the signal.send and will be available in the observer
return data
@joined_chat_handler.groups_for_signal
def joined_chat_handler(self, instance, **kwargs):
yield f'chat__{instance}'
@joined_chat_handler.groups_for_consumer
def joined_chat_handler(self, chat, **kwargs):
if chat:
yield f'chat__{chat}'
@action()
async def subscribe_joined(self, chat_id, request_id, **kwargs):
await self.joined_chat_handler.subscribe(chat_id, request_id=request_id) |
Beta Was this translation helpful? Give feedback.
0 replies
-
@Randix6644 sorry of the slow response the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
what are groups_for_signal and groups_for_consumer for? I've read the documents but still have no clue about them.
And I don't get what " f'chat__{instance}'" means in the example, what does "__" mean in this case?
Beta Was this translation helpful? Give feedback.
All reactions