daphne/channels/worker.py
2015-06-08 12:40:47 -07:00

20 lines
625 B
Python

class Worker(object):
"""
A "worker" process that continually looks for available messages to run
and runs their consumers.
"""
def __init__(self, channel_layer):
self.channel_layer = channel_layer
def run(self):
"""
Tries to continually dispatch messages to consumers.
"""
channels = self.channel_layer.registry.all_channel_names()
while True:
channel, message = self.channel_layer.receive_many(channels)
consumer = self.channel_layer.registry.consumer_for_channel(channel)
consumer(**message)