pitrou commented on code in PR #36986:
URL: https://github.com/apache/arrow/pull/36986#discussion_r1303210603
##########
python/pyarrow/_flight.pyx:
##########
@@ -1219,6 +1225,66 @@ cdef class FlightMetadataWriter(_Weakrefable):
check_flight_status(self.writer.get().WriteMetadata(deref(buf)))
+class AsyncioCall:
+ """State for an async RPC using asyncio."""
+
+ def __init__(self) -> None:
+ import asyncio
+ self._future = asyncio.get_running_loop().create_future()
+
+ def as_awaitable(self) -> object:
+ return self._future
+
+ def wakeup(self, result_or_exception) -> None:
+ # Mark the Future done from within its loop (asyncio
+ # objects are generally not thread-safe)
+ loop = self._future.get_loop()
+ if isinstance(result_or_exception, BaseException):
+ loop.call_soon_threadsafe(
+ self._future.set_exception, result_or_exception)
+ else:
+ loop.call_soon_threadsafe(
+ self._future.set_result, result_or_exception)
+
+
+cdef class AsyncioFlightClient:
+ """
+ A FlightClient with an asyncio-based async interface.
+
+ This interface is EXPERIMENTAL.
+ """
+
+ cdef:
+ FlightClient _client
+
+ def __init__(self, FlightClient client) -> None:
+ self._client = client
+
+ async def get_flight_info(
+ self,
+ descriptor: FlightDescriptor,
+ *,
+ options: FlightCallOptions = None,
+ ):
+ call = AsyncioCall()
+ self._get_flight_info(call, descriptor, options)
+ return await call.as_awaitable()
Review Comment:
This could just be:
```suggestion
def get_flight_info(
self,
descriptor: FlightDescriptor,
*,
options: FlightCallOptions = None,
):
call = AsyncioCall()
self._get_flight_info(call, descriptor, options)
return call.as_awaitable()
```
but I've kept the explicit `async def` for introspection and
self-documentation... what do you think @jorisvandenbossche ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]