@@ -212,6 +212,7 @@ open class URLSession : NSObject {
212
212
self . workQueue = DispatchQueue ( label: " URLSession< \( identifier) > " )
213
213
self . taskAttributesIsolation = DispatchQueue ( label: " URLSession< \( identifier) >.taskAttributes " , attributes: DispatchQueue . Attributes. concurrent)
214
214
self . delegateQueue = OperationQueue ( )
215
+ self . delegateQueue. maxConcurrentOperationCount = 1
215
216
self . delegate = nil
216
217
//TODO: Make sure this one can't be written to?
217
218
// Could create a subclass of URLSessionConfiguration that wraps the
@@ -221,12 +222,22 @@ open class URLSession : NSObject {
221
222
self . _configuration = c
222
223
self . multiHandle = _MultiHandle ( configuration: c, workQueue: workQueue)
223
224
}
225
+
226
+ /*
227
+ * A delegate queue should be serial to ensure correct ordering of callbacks.
228
+ * However, if user supplies a concurrent delegateQueue it is not converted to serial.
229
+ */
224
230
public /*not inherited*/ init ( configuration: URLSessionConfiguration , delegate: URLSessionDelegate ? , delegateQueue queue: OperationQueue ? ) {
225
231
initializeLibcurl ( )
226
232
identifier = nextSessionIdentifier ( )
227
233
self . workQueue = DispatchQueue ( label: " URLSession< \( identifier) > " )
228
234
self . taskAttributesIsolation = DispatchQueue ( label: " URLSession< \( identifier) >.taskAttributes " , attributes: DispatchQueue . Attributes. concurrent)
229
- self . delegateQueue = queue ?? OperationQueue ( )
235
+ if let _queue = queue {
236
+ self . delegateQueue = _queue
237
+ } else {
238
+ self . delegateQueue = OperationQueue ( )
239
+ self . delegateQueue. maxConcurrentOperationCount = 1
240
+ }
230
241
self . delegate = delegate
231
242
//TODO: Make sure this one can't be written to?
232
243
// Could create a subclass of URLSessionConfiguration that wraps the
0 commit comments