mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 15:47:06 +08:00
tidying async messaging
This commit is contained in:
parent
c8a6c3733d
commit
e9cd9a922b
1
.idea/dictionaries/ericf.xml
generated
1
.idea/dictionaries/ericf.xml
generated
@ -2355,6 +2355,7 @@
|
|||||||
<w>touchpad</w>
|
<w>touchpad</w>
|
||||||
<w>tournamententry</w>
|
<w>tournamententry</w>
|
||||||
<w>tournamentscores</w>
|
<w>tournamentscores</w>
|
||||||
|
<w>tpimportex</w>
|
||||||
<w>tpimports</w>
|
<w>tpimports</w>
|
||||||
<w>tplayer</w>
|
<w>tplayer</w>
|
||||||
<w>tpos</w>
|
<w>tpos</w>
|
||||||
|
|||||||
@ -1074,6 +1074,7 @@
|
|||||||
<w>touchpad</w>
|
<w>touchpad</w>
|
||||||
<w>toucs</w>
|
<w>toucs</w>
|
||||||
<w>toutf</w>
|
<w>toutf</w>
|
||||||
|
<w>tpimportex</w>
|
||||||
<w>tpimports</w>
|
<w>tpimports</w>
|
||||||
<w>tracebacks</w>
|
<w>tracebacks</w>
|
||||||
<w>tracestr</w>
|
<w>tracestr</w>
|
||||||
|
|||||||
@ -180,14 +180,9 @@ class _BoundTestSyncMessageReceiver:
|
|||||||
self._receiver = receiver
|
self._receiver = receiver
|
||||||
|
|
||||||
def handle_raw_message(self, message: bytes) -> bytes:
|
def handle_raw_message(self, message: bytes) -> bytes:
|
||||||
"""Handle a raw incoming synchronous message."""
|
"""Synchronously handle a raw incoming message."""
|
||||||
return self._receiver.handle_raw_message(self._obj, message)
|
return self._receiver.handle_raw_message(self._obj, message)
|
||||||
|
|
||||||
async def handle_raw_message_async(self, message: bytes) -> bytes:
|
|
||||||
"""Handle a raw incoming asynchronous message."""
|
|
||||||
return await self._receiver.handle_raw_message_async(
|
|
||||||
self._obj, message)
|
|
||||||
|
|
||||||
|
|
||||||
# RCVS_CODE_TEST_END
|
# RCVS_CODE_TEST_END
|
||||||
# RCVA_CODE_TEST_BEGIN
|
# RCVA_CODE_TEST_BEGIN
|
||||||
@ -244,12 +239,8 @@ class _BoundTestAsyncMessageReceiver:
|
|||||||
self._obj = obj
|
self._obj = obj
|
||||||
self._receiver = receiver
|
self._receiver = receiver
|
||||||
|
|
||||||
def handle_raw_message(self, message: bytes) -> bytes:
|
async def handle_raw_message(self, message: bytes) -> bytes:
|
||||||
"""Handle a raw incoming synchronous message."""
|
"""Asynchronously handle a raw incoming message."""
|
||||||
return self._receiver.handle_raw_message(self._obj, message)
|
|
||||||
|
|
||||||
async def handle_raw_message_async(self, message: bytes) -> bytes:
|
|
||||||
"""Handle a raw incoming asynchronous message."""
|
|
||||||
return await self._receiver.handle_raw_message_async(
|
return await self._receiver.handle_raw_message_async(
|
||||||
self._obj, message)
|
self._obj, message)
|
||||||
|
|
||||||
@ -419,7 +410,7 @@ def test_full_pipeline() -> None:
|
|||||||
# (we can do sync or async receivers)
|
# (we can do sync or async receivers)
|
||||||
if isinstance(self._target, TestClassRSync):
|
if isinstance(self._target, TestClassRSync):
|
||||||
return self._target.receiver.handle_raw_message(data)
|
return self._target.receiver.handle_raw_message(data)
|
||||||
return await self._target.receiver.handle_raw_message_async(data)
|
return await self._target.receiver.handle_raw_message(data)
|
||||||
|
|
||||||
class TestClassRSync:
|
class TestClassRSync:
|
||||||
"""Test class incorporating synchronous receive functionality."""
|
"""Test class incorporating synchronous receive functionality."""
|
||||||
|
|||||||
@ -279,8 +279,10 @@ class MessageProtocol:
|
|||||||
|
|
||||||
if part == 'sender':
|
if part == 'sender':
|
||||||
importlines1 = 'from efro.message import MessageSender'
|
importlines1 = 'from efro.message import MessageSender'
|
||||||
|
tpimportex = ''
|
||||||
else:
|
else:
|
||||||
importlines1 = 'from efro.message import MessageReceiver'
|
importlines1 = 'from efro.message import MessageReceiver'
|
||||||
|
tpimportex = ', Awaitable'
|
||||||
|
|
||||||
out = ('# Released under the MIT License. See LICENSE for details.\n'
|
out = ('# Released under the MIT License. See LICENSE for details.\n'
|
||||||
f'#\n'
|
f'#\n'
|
||||||
@ -293,7 +295,8 @@ class MessageProtocol:
|
|||||||
f'{importlines1}\n'
|
f'{importlines1}\n'
|
||||||
f'\n'
|
f'\n'
|
||||||
f'if TYPE_CHECKING:\n'
|
f'if TYPE_CHECKING:\n'
|
||||||
f' from typing import Union, Any, Optional, Callable\n'
|
f' from typing import Union, Any, Optional, Callable'
|
||||||
|
f'{tpimportex}\n'
|
||||||
f'{importlines2}'
|
f'{importlines2}'
|
||||||
f'\n'
|
f'\n'
|
||||||
f'\n')
|
f'\n')
|
||||||
@ -480,19 +483,23 @@ class MessageProtocol:
|
|||||||
f' ) -> None:\n'
|
f' ) -> None:\n'
|
||||||
f' assert obj is not None\n'
|
f' assert obj is not None\n'
|
||||||
f' self._obj = obj\n'
|
f' self._obj = obj\n'
|
||||||
f' self._receiver = receiver\n'
|
f' self._receiver = receiver\n')
|
||||||
f'\n'
|
if is_async:
|
||||||
f' def handle_raw_message(self, message: bytes) -> bytes:\n'
|
out += (
|
||||||
f' """Handle a raw incoming synchronous message."""\n'
|
'\n'
|
||||||
f' return self._receiver.handle_raw_message'
|
' async def handle_raw_message(self, message: bytes)'
|
||||||
f'(self._obj, message)\n'
|
' -> bytes:\n'
|
||||||
f'\n'
|
' """Asynchronously handle a raw incoming message."""\n'
|
||||||
f' async def handle_raw_message_async(self, message: bytes)'
|
' return await'
|
||||||
f' -> bytes:\n'
|
' self._receiver.handle_raw_message_async(\n'
|
||||||
f' """Handle a raw incoming asynchronous message."""\n'
|
' self._obj, message)\n')
|
||||||
f' return await'
|
else:
|
||||||
f' self._receiver.handle_raw_message_async(\n'
|
out += (
|
||||||
f' self._obj, message)\n')
|
'\n'
|
||||||
|
' def handle_raw_message(self, message: bytes) -> bytes:\n'
|
||||||
|
' """Synchronously handle a raw incoming message."""\n'
|
||||||
|
' return self._receiver.handle_raw_message'
|
||||||
|
'(self._obj, message)\n')
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -744,6 +751,7 @@ class MessageReceiver:
|
|||||||
|
|
||||||
def handle_raw_message(self, bound_obj: Any, msg: bytes) -> bytes:
|
def handle_raw_message(self, bound_obj: Any, msg: bytes) -> bytes:
|
||||||
"""Decode, handle, and return an encoded response for a message."""
|
"""Decode, handle, and return an encoded response for a message."""
|
||||||
|
assert not self.is_async, "can't call sync handler on async receiver"
|
||||||
try:
|
try:
|
||||||
msg_decoded, msgtype = self._decode_incoming_message(msg)
|
msg_decoded, msgtype = self._decode_incoming_message(msg)
|
||||||
handler = self._handlers.get(msgtype)
|
handler = self._handlers.get(msgtype)
|
||||||
@ -761,6 +769,7 @@ class MessageReceiver:
|
|||||||
|
|
||||||
The return value is the raw response to the message.
|
The return value is the raw response to the message.
|
||||||
"""
|
"""
|
||||||
|
assert self.is_async, "can't call async handler on sync receiver"
|
||||||
try:
|
try:
|
||||||
msg_decoded, msgtype = self._decode_incoming_message(msg)
|
msg_decoded, msgtype = self._decode_incoming_message(msg)
|
||||||
handler = self._handlers.get(msgtype)
|
handler = self._handlers.get(msgtype)
|
||||||
|
|||||||
@ -235,6 +235,21 @@ def check_clean_safety() -> None:
|
|||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
|
|
||||||
|
def gen_empty_py_init() -> None:
|
||||||
|
"""Generate an empty __init__.py for a package dir.
|
||||||
|
|
||||||
|
Used as part of meta builds.
|
||||||
|
"""
|
||||||
|
from efro.terminal import Clr
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
raise Exception('Expected a single path arg.')
|
||||||
|
outpath = Path(sys.argv[2])
|
||||||
|
outpath.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
print(f'Meta-building {Clr.BLD}{outpath}{Clr.RST}')
|
||||||
|
with open(outpath, 'w', encoding='utf-8') as outfile:
|
||||||
|
outfile.write('# This file is autogenerated; do not hand-edit.\n')
|
||||||
|
|
||||||
|
|
||||||
def formatcode() -> None:
|
def formatcode() -> None:
|
||||||
"""Format all of our C/C++/etc. code."""
|
"""Format all of our C/C++/etc. code."""
|
||||||
import efrotools.code
|
import efrotools.code
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user