Skip to content

Instantly share code, notes, and snippets.

@MaximBazarov
Created March 3, 2019 16:42
Show Gist options
  • Save MaximBazarov/8f14c8c4372a63ed5d312f3614f1298b to your computer and use it in GitHub Desktop.
Save MaximBazarov/8f14c8c4372a63ed5d312f3614f1298b to your computer and use it in GitHub Desktop.
import Foundation
/// Gives your value thread protection
public final class AtomicValue<T> {
public var value: T {
get {
return lock.sync {
return self._value
}
}
set {
lock.async {
self._value = newValue
}
}
}
private let lock = DispatchQueue(label: "code.unicore.atomic-value-lock")
private var _value: T
public init(_ value: T) {
self._value = value
}
}
@orchidfire
Copy link

This doesnt work

@MaximBazarov
Copy link
Author

This doesnt work

Could you elaborate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment