o
    >h                     @   s(   d dl Z d dlmZ G dd deZdS )    N)StatelessServerc                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
Workerz
    ASGI protocol server that surfaces events sent to specific channels
    on the channel layer into a single application instance.
      c                    s0   t  || || _|| _| jd u rtdd S )NzChannel layer is not valid)super__init__channelschannel_layer
ValueError)selfapplicationr   r   max_applications	__class__ o/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/channels/worker.pyr      s   
zWorker.__init__c                    sJ   g }| j D ]}|t| | qt|I dH  dd |D  dS )zP
        Listens on all the provided channels and handles the messages.
        Nc                 S   s   g | ]}|  qS r   )result).0listenerr   r   r   
<listcomp>   s    z!Worker.handle.<locals>.<listcomp>)r   appendasyncioensure_futurer   wait)r
   	listenerschannelr   r   r   handle   s   
zWorker.handlec                    sR   	 | j |I dH }|ddstdd|d}| ||}||I dH  q)z)
        Single-channel listener
        TNtypez%Worker received message with no type.r   )r   r   )r   receivegetr	   "get_or_create_application_instanceput)r
   r   messagescopeinstance_queuer   r   r   r       s   
zWorker.listener)r   )__name__
__module____qualname____doc__r   r   r   __classcell__r   r   r   r   r      s
    r   )r   asgiref.serverr   r   r   r   r   r   <module>   s    