Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocols do not support async callbacks #405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading