Skip to content

Commit 2e1ddfd

Browse files
committed
Get rid of rx.Observable django channels example, async is simpler
1 parent a99c1cf commit 2e1ddfd

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

  • examples/django_channels2/django_channels2

examples/django_channels2/django_channels2/schema.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import asyncio
2+
13
import graphene
2-
from rx import Observable
3-
from channels.layers import get_channel_layer
44
from asgiref.sync import async_to_sync
5+
from channels.layers import get_channel_layer
56

67
channel_layer = get_channel_layer()
78

@@ -32,12 +33,12 @@ class Subscription(graphene.ObjectType):
3233
count_seconds = graphene.Int(up_to=graphene.Int())
3334
new_message = graphene.String()
3435

35-
def resolve_count_seconds(self, info, up_to=5):
36-
return (
37-
Observable.interval(1000)
38-
.map(lambda i: "{0}".format(i))
39-
.take_while(lambda i: int(i) <= up_to)
40-
)
36+
async def resolve_count_seconds(self, info, up_to=5):
37+
i = 1
38+
while i <= up_to:
39+
yield str(i)
40+
await asyncio.sleep(1)
41+
i += 1
4142

4243
async def resolve_new_message(self, info):
4344
channel_name = await channel_layer.new_channel()

0 commit comments

Comments
 (0)