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