Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Sep 28, 2023
1 parent 46ddb24 commit a704e9a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 29 deletions.
Empty file removed examples/__init__.py
Empty file.
7 changes: 3 additions & 4 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from aiostream import stream, pipe

from aiostream import pipe, stream


async def main():
Expand Down Expand Up @@ -33,6 +34,4 @@ async def main():


# Run main coroutine
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
asyncio.run(main())
4 changes: 1 addition & 3 deletions examples/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ async def main():


# Run main coroutine
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
asyncio.run(main())
21 changes: 7 additions & 14 deletions examples/norm_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""

import asyncio
from aiostream import stream, pipe

from aiostream import pipe, stream

# Constants

Expand Down Expand Up @@ -85,26 +86,18 @@ def square_root(x):
# Main function


def run_server(bind="127.0.0.1", port=8888):
async def main(bind="127.0.0.1", port=8888):
# Start the server
loop = asyncio.get_event_loop()
coro = asyncio.start_server(euclidean_norm_handler, bind, port)
server = loop.run_until_complete(coro)
server = await asyncio.start_server(euclidean_norm_handler, bind, port)

# Serve requests until Ctrl+C is pressed
print("Serving on {}".format(server.sockets[0].getsockname()))
try:
loop.run_forever()
except KeyboardInterrupt:
pass

# Close the server
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
async with server:
await server.serve_forever()


# Main execution

if __name__ == "__main__":
run_server()
asyncio.run(main())
7 changes: 3 additions & 4 deletions examples/preserve.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from aiostream import stream, operator

from aiostream import operator, stream


async def main():
Expand All @@ -26,6 +27,4 @@ async def agen():


# Run main coroutine
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
asyncio.run(main())
7 changes: 3 additions & 4 deletions examples/simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from aiostream import stream, pipe

from aiostream import pipe, stream


async def main():
Expand All @@ -16,6 +17,4 @@ async def main():


# Run main coroutine
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
asyncio.run(main())

0 comments on commit a704e9a

Please sign in to comment.