Skip to content

Commit

Permalink
Make groups actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Jul 13, 2015
1 parent 3a48478 commit 964c457
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion channels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
monkeypatch_django()

# Promote channel to top-level (down here to avoid circular import errs)
from .channel import Channel
from .channel import Channel, Group
10 changes: 5 additions & 5 deletions channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ class Group(object):
of the group after an expiry time (keep re-adding to keep them in).
"""

def __init__(self, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None):
def __init__(self, name, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None):
self.name = name
if channel_backend:
self.channel_backend = channel_backend
else:
self.channel_backend = channel_backends[alias]

def add(self, channel):
self.channel_backend.add(self.name, channel)
self.channel_backend.group_add(self.name, channel)

def discard(self, channel):
self.channel_backend.discard(self.name, channel)
self.channel_backend.group_discard(self.name, channel)

def channels(self):
self.channel_backend.channels(self.name)
self.channel_backend.group_channels(self.name)

def send(self, **kwargs):
self.channel_backend.send_group(self, self.name, kwargs)
self.channel_backend.send_group(self.name, kwargs)
4 changes: 3 additions & 1 deletion channels/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND


def consumer(self, alias=DEFAULT_CHANNEL_BACKEND, *channels):
def consumer(*channels, **kwargs):
"""
Decorator that registers a function as a consumer.
"""
# We can't put a kwarg after *args in py2
alias = kwargs.get("alias", DEFAULT_CHANNEL_BACKEND)
# Upconvert if you just pass in a string
if isinstance(channels, six.string_types):
channels = [channels]
Expand Down

0 comments on commit 964c457

Please sign in to comment.