File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -72,8 +72,8 @@ This would also work with async-await syntax in Python 3
7272
7373.. code-block :: python
7474
75+ import asyncio
7576 from streamz import Stream
76- from tornado.ioloop import IOLoop
7777
7878 async def f ():
7979 source = Stream(asynchronous = True ) # tell the stream we're working asynchronously
@@ -82,7 +82,28 @@ This would also work with async-await syntax in Python 3
8282 for x in range (10 ):
8383 await source.emit(x)
8484
85- IOLoop().run_sync(f)
85+ asyncio.run(f())
86+
87+ When working asynchronously, we can also map asynchronous functions.
88+
89+ .. code-block :: python
90+
91+ async def increment_async (x ):
92+ """ A "long-running" increment function
93+
94+ Simulates a function that does real asyncio work.
95+ """
96+ await asyncio.sleep(0.1 )
97+ return x + 1
98+
99+ async def f_inc ():
100+ source = Stream(asynchronous = True ) # tell the stream we're working asynchronously
101+ source.map_async(increment_async).rate_limit(0.500 ).sink(write)
102+
103+ for x in range (10 ):
104+ await source.emit(x)
105+
106+ asyncio.run(f_inc())
86107
87108
88109 Event Loop on a Separate Thread
You can’t perform that action at this time.
0 commit comments