예제 #1
0
    def iterator(self):
        # get the class object from settings (or default if not specified).
        Backend = class_from_str(SSE_BACKEND_CLASS)

        # create a backend instance and subscribe the channel.
        backend = Backend()
        backend.subscribe(self.channel)

        for event, data in backend.listen():
            self.sse.add_message(event, data)
            yield
예제 #2
0
# -*- coding: utf-8 -*-
from django.conf import settings
from utils import class_from_str


# create a reference to the backend class.
SseBackendClass = class_from_str(getattr(settings, 'SSE_BACKEND_CLASS'))


def send_event(event, data, channel):
    '''
    A handy function to send an event to a particular channel.

    Arguments:
      event     -- the name of the event to be sent.
      data      -- data (dict) to be sent along with the event.
      channel   -- the name of the channel to send event to.
    '''
    SseBackendClass().send_event(event, data, channel)