Skip to content

Commit

Permalink
Merge pull request mosquito#493 from Olegt0rr/hide-loop
Browse files Browse the repository at this point in the history
Remove `loop` params
  • Loading branch information
mosquito authored Oct 11, 2023
2 parents 478b3e9 + ff3cc46 commit 0e5db7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
3 changes: 1 addition & 2 deletions docs/source/examples/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ async def main() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.run(main())
8 changes: 3 additions & 5 deletions docs/source/examples/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@


async def main() -> None:
loop = asyncio.get_event_loop()

async def get_connection() -> AbstractRobustConnection:
return await aio_pika.connect_robust("amqp://guest:guest@localhost/")

connection_pool: Pool = Pool(get_connection, max_size=2, loop=loop)
connection_pool: Pool = Pool(get_connection, max_size=2)

async def get_channel() -> aio_pika.Channel:
async with connection_pool.acquire() as connection:
return await connection.channel()

channel_pool: Pool = Pool(get_channel, max_size=10, loop=loop)
channel_pool: Pool = Pool(get_channel, max_size=10)
queue_name = "pool_queue"

async def consume() -> None:
Expand All @@ -41,7 +39,7 @@ async def publish() -> None:
)

async with connection_pool, channel_pool:
task = loop.create_task(consume())
task = asyncio.create_task(consume())
await asyncio.wait([publish() for _ in range(50)])
await task

Expand Down
9 changes: 3 additions & 6 deletions docs/source/rabbitmq-tutorial/examples/6-rpc/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ class FibonacciRpcClient:
connection: AbstractConnection
channel: AbstractChannel
callback_queue: AbstractQueue
loop: asyncio.AbstractEventLoop

def __init__(self) -> None:
self.futures: MutableMapping[str, asyncio.Future] = {}
self.loop = asyncio.get_running_loop()

async def connect(self) -> "FibonacciRpcClient":
self.connection = await connect(
"amqp://guest:guest@localhost/", loop=self.loop,
)
self.connection = await connect("amqp://guest:guest@localhost/")
self.channel = await self.connection.channel()
self.callback_queue = await self.channel.declare_queue(exclusive=True)
await self.callback_queue.consume(self.on_response, no_ack=True)
Expand All @@ -38,7 +34,8 @@ async def on_response(self, message: AbstractIncomingMessage) -> None:

async def call(self, n: int) -> int:
correlation_id = str(uuid.uuid4())
future = self.loop.create_future()
loop = asyncio.get_running_loop()
future = loop.create_future()

self.futures[correlation_id] = future

Expand Down

0 comments on commit 0e5db7f

Please sign in to comment.