Skip to content

Commit

Permalink
Protocols do not support async callbacks (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-wolf-oberholtzer authored Sep 23, 2024
1 parent 1f1aa2b commit 63be8c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
13 changes: 4 additions & 9 deletions supriya/osc/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ async def _disconnect(self, panicked: bool = False) -> None:
async def _on_connect(self, *, boot_future: FutureLike[bool]) -> None:
super()._on_connect(boot_future=self.boot_future)
if self.on_connect_callback:
if asyncio.iscoroutine(result := self.on_connect_callback()):
await result
self.on_connect_callback()

async def _on_disconnect(
self,
Expand All @@ -71,11 +70,9 @@ async def _on_disconnect(
panicked=panicked,
)
if panicked and self.on_panic_callback:
if asyncio.iscoroutine(result := self.on_panic_callback()):
await result
self.on_panic_callback()
elif not panicked and self.on_disconnect_callback:
if asyncio.iscoroutine(result := self.on_disconnect_callback()):
await result
self.on_disconnect_callback()

async def _on_healthcheck_passed(self, message: OscMessage) -> None:
super()._on_healthcheck_passed(message)
Expand Down Expand Up @@ -161,9 +158,7 @@ async def connect(
lambda: self, remote_addr=(ip_address, port)
)
if self.healthcheck and self.healthcheck.active:
self.healthcheck_task = asyncio.get_running_loop().create_task(
self._run_healthcheck()
)
self.healthcheck_task = loop.create_task(self._run_healthcheck())
elif not self.healthcheck:
await self._on_connect(boot_future=self.boot_future)

Expand Down
9 changes: 3 additions & 6 deletions supriya/scsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ async def boot(self, options: Options) -> None:
await self.exit_future
raise ServerCannotBoot(self.error_text)
if self.on_boot_callback:
if asyncio.iscoroutine(result := self.on_boot_callback()):
loop.create_task(result)
self.on_boot_callback()

def connection_made(self, transport) -> None:
logger.info(
Expand Down Expand Up @@ -534,11 +533,9 @@ def process_exited(self) -> None:
except asyncio.exceptions.InvalidStateError:
pass
if was_quitting and self.on_quit_callback:
if asyncio.iscoroutine(result := self.on_quit_callback()):
asyncio.get_running_loop().create_task(result)
self.on_quit_callback()
elif not was_quitting and self.on_panic_callback:
if asyncio.iscoroutine(result := self.on_panic_callback()):
asyncio.get_running_loop().create_task(result)
self.on_panic_callback()

async def quit(self) -> None:
if not self._quit():
Expand Down

0 comments on commit 63be8c7

Please sign in to comment.