Skip to content

Commit

Permalink
refactor: migrate to using asyncio.create_task (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jan 24, 2025
1 parent f8bd9c6 commit 1791bdb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/aioharmony/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ async def run():
hub_ips = args.harmony_ip.split(",")
for hub in hub_ips:
# Connect to the HUB
hub_tasks.append(asyncio.ensure_future(execute_per_hub(hub, args)))
hub_tasks.append(asyncio.create_task(execute_per_hub(hub, args)))

results = await asyncio.gather(*hub_tasks, return_exceptions=True)
for result in results:
Expand Down
2 changes: 1 addition & 1 deletion src/aioharmony/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def wrapped():
return wrapped

partial_func = async_partial(callback, result)
task = asyncio.ensure_future(partial_func())
task = asyncio.create_task(partial_func())
_CALLBACK_TASKS.add(task)
task.add_done_callback(_CALLBACK_TASKS.discard)
return True
Expand Down
4 changes: 2 additions & 2 deletions src/aioharmony/hubconnector_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def hub_connect(self, is_reconnect: bool = False) -> bool:

# Now put the listener on the loop.
if not self._listener_task:
self._listener_task = asyncio.ensure_future(
self._listener_task = asyncio.create_task(
self._listener(self._websocket)
)

Expand Down Expand Up @@ -301,7 +301,7 @@ async def hub_send(
"Accept-Charset": "utf-8",
}
json_request = {"id ": msgid, "cmd": command, "params": {}}
response = asyncio.ensure_future(self.hub_post(url, json_request, headers))
response = asyncio.create_task(self.hub_post(url, json_request, headers))
return response

# Make sure we're connected.
Expand Down
2 changes: 1 addition & 1 deletion src/aioharmony/responsehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, message_queue: asyncio.Queue, name: str = None) -> None:
self._name = name
self._handler_list = []

self._callback_task = asyncio.ensure_future(self._callback_handler())
self._callback_task = asyncio.create_task(self._callback_handler())

async def close(self):
"""
Expand Down

0 comments on commit 1791bdb

Please sign in to comment.