File tree Expand file tree Collapse file tree
examples/django_channels2/django_channels2 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import asyncio
2+
13import graphene
2- from rx import Observable
3- from channels .layers import get_channel_layer
44from asgiref .sync import async_to_sync
5+ from channels .layers import get_channel_layer
56
67channel_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 ()
You can’t perform that action at this time.
0 commit comments