mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-23 19:36:26 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
53 lines
1.1 KiB
Swift
53 lines
1.1 KiB
Swift
//
|
|
// Atomic.swift
|
|
//
|
|
//
|
|
// Created by Vladislav Lisianskii on 23.02.2022.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@propertyWrapper
|
|
public final class Atomic<Value> {
|
|
|
|
private var value: Value
|
|
|
|
private let queue = DispatchQueue(
|
|
label: "com.xcodegencore.atomic.\(UUID().uuidString)",
|
|
qos: .utility,
|
|
attributes: .concurrent,
|
|
autoreleaseFrequency: .inherit,
|
|
target: .global()
|
|
)
|
|
|
|
public init(wrappedValue: Value) {
|
|
self.value = wrappedValue
|
|
}
|
|
|
|
public var wrappedValue: Value {
|
|
get {
|
|
queue.sync { value }
|
|
}
|
|
set {
|
|
queue.async(flags: .barrier) { [weak self] in
|
|
self?.value = newValue
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Allows us to get the actual `Atomic` instance with the $
|
|
/// prefix.
|
|
public var projectedValue: Atomic<Value> {
|
|
return self
|
|
}
|
|
|
|
/// Modifies the protected value using `closure`.
|
|
public func with<R>(
|
|
_ closure: (inout Value) throws -> R
|
|
) rethrows -> R {
|
|
try queue.sync(flags: .barrier) {
|
|
try closure(&value)
|
|
}
|
|
}
|
|
}
|