Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Modules/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/wpxmlrpc", from: "0.9.0"),
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", revision: "b34794c9a3f32312e1593d4a3d120572afa0d010"),
.package(url: "https://github.com/zendesk/support_sdk_ios", from: "8.0.3"),
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.10.1"),
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.12.1"),
// We can't use wordpress-rs branches nor commits here. Only tags work.
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20251101"),
.package(
Expand Down
64 changes: 64 additions & 0 deletions Modules/Sources/WordPressCore/Types/LockingHashMap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Foundation

public class LockingHashMap<Value>: @unchecked Sendable {
let lock = NSLock()

var list: [AnyHashable: Value] = [:]

public init(_ values: [AnyHashable: Value] = [:]) {
self.list = values
}

public subscript(_ key: AnyHashable) -> Value? {
get {
lock.withLock {
list[key]
}
}
set {
lock.withLock {
list[key] = newValue
}
}
}

public var values: Dictionary<AnyHashable, Value>.Values {
lock.withLock {
self.list.values
}
}

@discardableResult
public func removeValue(forKey key: AnyHashable) -> Value? {
lock.withLock {
self.list.removeValue(forKey: key)
}
}

public func removeAll() {
lock.withLock {
self.list.removeAll()
}
}
}

public class LockingTaskHashMap<T, E>: LockingHashMap<Task<T, E>>, @unchecked Sendable where T: Sendable, E: Error {

@discardableResult
public override func removeValue(forKey key: AnyHashable) -> Task<T, E>? {
lock.withLock {
let task = self.list.removeValue(forKey: key)
task?.cancel()
return task
}
}

public override func removeAll() {
lock.withLock {
for key in self.list.keys {
let task = self.list.removeValue(forKey: key)
task?.cancel()
}
}
}
}
Loading