Closed jakaplan closed 2 years ago
@amomchilov For your review. I dislike how much code duplication this introduces, but I couldn't figure out a way to reduce it due to the cascading nature of async
.
Until then, could you help me understand when a callback should be
async
?
When the API user wants to create a callback which uses async
functions within it, which will be an increasing percentage of functions over time. Without this the caller can't have any route with a reply (or one they want an error to be propagated back from) use async
functions because wrapping the code in a Task
won't allow for the return value (or thrown error) to be returned.
A realistic example could be an XPC service with a route provided a URL to a PDF. The service needs to download and then parse the PDF to extract some data. PDFs are a notorious exploit vector, so breaking out this component into an XPC service would be prudent. Using async
functions to perform the download would be easiest. And there very well could be async
functions involved in the data extraction (ex. running ML inference over it to extract text embedded in images).
When the API user wants to create a callback which uses
async
functions within it, which will be an increasing percentage of functions over time. Without this the caller can't have any route with a reply (or one they want an error to be propagated back from) useasync
functions because wrapping the code in aTask
won't allow for the return value (or thrown error) to be returned.
Ah yes, that makes perfect sense, thanks for the explanation
Adds tests to match