Skip to content

Commit 3481ca0

Browse files
authored
Merge pull request #986 from mamabusi/swift-3.1-branch
2 parents 5a2ad45 + 33ca6a3 commit 3481ca0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Foundation/NSURLSession/NSURLSession.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ open class URLSession : NSObject {
212212
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
213213
self.taskAttributesIsolation = DispatchQueue(label: "URLSession<\(identifier)>.taskAttributes", attributes: DispatchQueue.Attributes.concurrent)
214214
self.delegateQueue = OperationQueue()
215+
self.delegateQueue.maxConcurrentOperationCount = 1
215216
self.delegate = nil
216217
//TODO: Make sure this one can't be written to?
217218
// Could create a subclass of URLSessionConfiguration that wraps the
@@ -221,12 +222,22 @@ open class URLSession : NSObject {
221222
self._configuration = c
222223
self.multiHandle = _MultiHandle(configuration: c, workQueue: workQueue)
223224
}
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+
*/
224230
public /*not inherited*/ init(configuration: URLSessionConfiguration, delegate: URLSessionDelegate?, delegateQueue queue: OperationQueue?) {
225231
initializeLibcurl()
226232
identifier = nextSessionIdentifier()
227233
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
228234
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+
}
230241
self.delegate = delegate
231242
//TODO: Make sure this one can't be written to?
232243
// Could create a subclass of URLSessionConfiguration that wraps the

0 commit comments

Comments
 (0)