Outline a callback pattern for implementing long poll methods
Opened this issue · 3 comments
Various entities provide a long poll mechanism to get changes as they occur on the server (I assume this is due to the lack of webhooks, which would be difficult to proxy in the current environment, and for clients like what we are building long poll would make sense in certain use cases).
The endpoints generally seem to return a response if there are any, otherwise return a 400
and hang up.
This ticket is to study these endpoints like cardholder
, alarms
, etc and determine a pattern so all of them can follow the same design principles.
See #18 comment on streaming message now that we have moved to asyncio
Given we are using async functions, we should just stick with using yield
to return objects as we receive them from the long poll endpoints.
While building the shillelagh
adapter see #31, I saw it uses the following pattern for returning rows of data. shillelagh
has the same pattern of querying an API and returning a SQL resulset.
It's worth noting the Iterator[Row]
+ yield
patter to return incremental results:
def get_data( # pylint: disable=too-many-locals
self,
bounds: Dict[str, Filter],
order: List[Tuple[str, RequestedOrder]],
**kwargs: Any,
) -> Iterator[Row]:
yield {
"rowid": 1,
"id": 1,
"authorised": True,
"first_name": "Dev",
"last_name": "Mukherjee",
}