Skip to content

[URLSessionTask] Use DispatchQueue.sync overload which has a return value #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions Foundation/NSURLSession/NSURLSessionTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,15 @@ open class URLSessionTask : NSObject, NSCopying {
/// May differ from originalRequest due to http server redirection
/*@NSCopying*/ open fileprivate(set) var currentRequest: URLRequest? {
get {
var r: URLRequest? = nil
taskAttributesIsolation.sync { r = self._currentRequest }
return r
return taskAttributesIsolation.sync { self._currentRequest }
}
//TODO: dispatch_barrier_async
set { taskAttributesIsolation.async(flags: .barrier) { self._currentRequest = newValue } }
}
fileprivate var _currentRequest: URLRequest? = nil
/*@NSCopying*/ open fileprivate(set) var response: URLResponse? {
get {
var r: URLResponse? = nil
taskAttributesIsolation.sync { r = self._response }
return r
return taskAttributesIsolation.sync { self._response }
}
set { taskAttributesIsolation.async(flags: .barrier) { self._response = newValue } }
}
Expand All @@ -166,9 +162,7 @@ open class URLSessionTask : NSObject, NSCopying {
/// Number of body bytes already received
open fileprivate(set) var countOfBytesReceived: Int64 {
get {
var r: Int64 = 0
taskAttributesIsolation.sync { r = self._countOfBytesReceived }
return r
return taskAttributesIsolation.sync { self._countOfBytesReceived }
}
set { taskAttributesIsolation.async(flags: .barrier) { self._countOfBytesReceived = newValue } }
}
Expand All @@ -177,9 +171,7 @@ open class URLSessionTask : NSObject, NSCopying {
/// Number of body bytes already sent */
open fileprivate(set) var countOfBytesSent: Int64 {
get {
var r: Int64 = 0
taskAttributesIsolation.sync { r = self._countOfBytesSent }
return r
return taskAttributesIsolation.sync { self._countOfBytesSent }
}
set { taskAttributesIsolation.async(flags: .barrier) { self._countOfBytesSent = newValue } }
}
Expand Down Expand Up @@ -209,9 +201,7 @@ open class URLSessionTask : NSObject, NSCopying {
*/
open var state: URLSessionTask.State {
get {
var r: URLSessionTask.State = .suspended
taskAttributesIsolation.sync { r = self._state }
return r
return taskAttributesIsolation.sync { self._state }
}
set { taskAttributesIsolation.async(flags: .barrier) { self._state = newValue } }
}
Expand Down Expand Up @@ -296,9 +286,7 @@ open class URLSessionTask : NSObject, NSCopying {
/// URLSessionTaskPriorityHigh, but use is not restricted to these.
open var priority: Float {
get {
var r: Float = 0
taskAttributesIsolation.sync { r = self._priority }
return r
return taskAttributesIsolation.sync { self._priority }
}
set {
taskAttributesIsolation.async(flags: .barrier) { self._priority = newValue }
Expand Down