I'm trying to wrap my head around all of the new Swift concurrency stuff and have been playing around with our networking stack to do so. Requests currently are passed to our network client and have a completion handler. The network client looks at how many requests are currently in-flight and will enqueue the newly-submitted request if we're already at the limit.
// Pseudocode func load( request: URLRequest, completion: @escaping (Result<(URLResponse, Data), Error>) -> Void )
Converting the actual underlying loading of the request is fairly straightforward — we could use
URLSession.data(for:delegate:) or similar async methods and update the function signature to be
async and return the
func load(request: URLRequest) async -> Result<(URLResponse, Data), Error>
However, I'm unsure of how to encapsulate the notion of "enqueue if we're already at max # of in-flight requests." Can somebody point me in the right direction? What would I return from the
load function in that case?