Last active
July 16, 2017 01:41
-
-
Save sarah-j-smith/393b53b6ef6e8b208fb91cdbe5a1a61f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request { | |
// DTO that can be accessed from different threads | |
// Note: this is faster/better/approved by Apple instead of @synchronized and | |
// other constructs (even tho' its a bit more verbose). DispatchQueue by | |
// default is Serial so this synchronizes accesses. | |
private var requestStateQueue = DispatchQueue(label: "requestStateQueue") | |
private var _cancelled = false | |
/** Set to true to cancel this request - atomic/threadsafe */ | |
var cancelled: Bool { | |
get { | |
var result = false | |
requestStateQueue.sync { | |
result = _cancelled | |
} | |
return result | |
} | |
set { | |
requestStateQueue.sync { | |
_cancelled = newValue | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment